The example in this article describes how jQuery implements the floating layer to scroll with the browser scroll bar. Share it with everyone for your reference. The details are as follows:
This is a floating layer effect implemented by jQuery. It scrolls with the browser scroll bar and remains at the top. Please use Firefox to test. The performance under IE is not ideal.
The screenshot of the running effect is as follows:
The online demo address is as follows:
http://demo.jb51.net/js/2015/jquery-float-follow-nav-style-codes/
The specific code is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>jquery浮动层随浏览器滚动条滚动</title> <script type="text/javascript" src="jquery-1.6.2.min.js"></script> <script type="text/javascript"> if ($.browser.version != "6.0") { $(window).scroll(function(){ if($(this).scrollTop()>118 &&(($(document).height()-$(this).scrollTop())>($(window).height()+$(".aysw-footer").innerHeight()))){ $("#c_left").css({position: 'fixed', top: '2px'}); }else{ if(($(document).height()-$(this).scrollTop())<=($(window).height()+$(".aysw-footer").innerHeight())){ $("#c_left").css({position: 'absolute', top:($(".aysw-footer").offset().top-$("#c_left").innerHeight()-$(".page-home").offset().top-20) +'px'}); }else{ $("#c_left").css({position: 'absolute', top: '2px'}); } } }); } </script> </head> <body style="height:auto; margin:0; padding:0"> <div style="height:118px;background:#6CF;">sadfsadfasfsafd</div> <div class="page-home" style="min-height:1500px;width:100%; background-color:#FFC; position:relative"> <div id="c_left" style="border:1px solid red; width:200px ;height:800px; color:white;background-color:#333; position:absolute; top:2px"> 羞涩的浮动层... </div> </div> <div class="aysw-footer" style="height:200px; width:100%; background-color:#0C3; position:relative"></div> </body> </html>
I hope this article will be helpful to everyone’s jQuery programming.