This article mainly introduces how some content in HTML pages can be fixed and not scrolled when scrolling, which is helpful for layout. Without further ado, the details are as follows: Effect screenshots: Page source code: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Untitled Page</title> </head> <body style="width: 900px; margin: 0px auto; line-height: 23px; padding: 10px;"> <div> <div style="float: left; width: 120px;"> <div> I will roll<br/> Scrolling content area<br/> Scrolling content area<br/> Scrolling content area<br/> </div> <div id="div1" style="border: solid 1px gray; width: 90px; padding: 10px; background-color: #eff;"> I don't scroll<br/> You look at me<br/><br/> I don't roll<br/> You look at me<br/><br/> I don't roll<br/> You look at me<br/><br/> I don't roll<br/> Look at me<br/><br/> </div> </div> <div style="float: right; width: 750px; border: solid 1px gray; padding: 10px;"> <span>ssssssssssssssss</span><br> <span>ssssssssssssssss</span><br> <span>ssssssssssssssss</span><br> <span>ssssssssssssssss</span><br> <span>ssssssssssssssss</span><br> <span>ssss I am the content ssss</span><br> <span>ssssssssssssssss</span><br> <span>sssssss I am the content sssssssss</span><br> <span>ssssssssssssssss</span><br> <span>sssssss I am the content sssssssss</span><br> <span>ssssssssssssssss</span><br> <span>ssssss I am the content ssssssssss</span><br> <span>ssssssssssssssss</span><br> <span>ssssssssssssssss</span><br><span>sssssssI am the contentssssssssss</span><br> <span>ssssssssssssssss</span><br> <span>ssssssssssssssss</span><br><span>sssssssI am the contentssssssssss</span><br> <span>ssssssssssssssss</span><br> <span>ssssssssssssssss</span><br><span>sssssssI am the contentssssssssss</span><br> <span>ssssssssssssssss</span><br> <span>ssssssssssssssss</span><br><span>sssssssI am the contentssssssssss</span><br> <span>ssssssssssssssss</span><br> <span>ssssssssssssssss</span><br><span>sssssssI am the contentssssssssss</span><br> <span>ssssssssssssssss</span><br> <span>ssssssssssssssss</span><br><span>sssssssI am the contentssssssssss</span><br> <span>ssssssssssssssss</span><br> <span>ssssssssssssssss</span><br><span>sssssssI am the contentssssssssss</span><br> <span>ssssssssssssssss</span><br> <span>ssssssssssssssss</span><br><span>sssssssI am the contentssssssssss</span><br> <span>ssssssssssssssss</span><br> <span>ssssssssssssssss</span><br><span>sssssssI am the contentssssssssss</span><br> <span>ssssssssssssssss</span><br> <span>ssssssssssssssss</span><br><span>sssssssI am the contentssssssssss</span><br> <span>ssssssssssssssss</span><br> <span>ssssssssssssssss</span><br><span>sssssssI am the contentssssssssss</span><br> <span>ssssssssssssssss</span><br> <span>ssssssssssssssss</span><br><span>sssssssI am the contentssssssssss</span><br> <span>ssssssssssssssss</span><br> <span>ssssssssssssssss</span><br><span>sssssssI am the contentssssssssss</span><br> <span>ssssssssssssssss</span><br> <span>ssssssssssssssss</span><br><span>sssssssI am the contentssssssssss</span><br> <span>ssssssssssssssss</span><br> <span>ssssssssssssssss</span><br><span>sssssssI am the contentssssssssss</span><br> <span>ssssssssssssssss</span><br> <span>ssssssssssssssss</span><br><span>sssssssI am the contentssssssssss</span><br> <span>ssssssssssssssss</span><br> <span>ssssssssssssssss</span><br> </div> </div> <script type="text/javascript"> function htmlScroll() { var top = document.body.scrollTop || document.documentElement.scrollTop; if (elFix.data_top < top) { elFix.style.position = 'fixed'; elFix.style.top = 0; elFix.style.left = elFix.data_left; } else { elFix.style.position = 'static'; } } function htmlPosition(obj) { var o = obj; var t = o.offsetTop; var l = o.offsetLeft; while (o = o.offsetParent) { t += o.offsetTop; l += o.offsetLeft; } obj.data_top = t; obj.data_left = l; } var oldHtmlWidth = document.documentElement.offsetWidth; window.onresize = function () { var newHtmlWidth = document.documentElement.offsetWidth; if (oldHtmlWidth == newHtmlWidth) { return; } oldHtmlWidth = newHtmlWidth; elFix.style.position = 'static'; htmlPosition(elFix); htmlScroll(); } window.onscroll = htmlScroll; var elFix = document.getElementById('div1'); htmlPosition(elFix); </script> </body> </html> This is the end of this article about how to keep some content in a fixed position when an HTML page scrolls. For more relevant HTML page scrolling content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! |
<<: Split and merge tables in HTML (colspan, rowspan)
>>: HTML+CSS box model example (circle, semicircle, etc.) "border-radius" is simple and easy to use
illustrate: There are two main types of nginx log...
While the paperless world has not yet emerged, mo...
Overview As for the current default network of Do...
Installation environment: CentOS7 64-bit, MySQL5....
This article example shares the specific code of ...
Step 1: Get the MySQL YUM source Go to the MySQL ...
Ubuntu is a free and open source desktop PC opera...
public function json_product_list($where, $order)...
Table of contents 1. Overview 1. Principle 2. Imp...
Table of contents Overview How to achieve it Spec...
After being tortured by the front-end cross-domai...
1. Check the maximum number of open files in the ...
Shtml and asp are similar. In files named shtml, s...
Recently, I need to package the project for membe...
Table of contents 1. What is syntactic sugar? 2. ...