Plug-in Requirements description
The jquery plugin is mainly resolved as the scroll bar scrolls to fix a div, and the mouse rolls with the float fixed at the top. When we scroll through the Web browsing, we want to anchor an ad or select article in the sidebar so that when the user rolls down, the sidebar is not blank, increasing exposure and click-through, increasing revenue and traffic.
Of course, sometimes when designing a Web page, the sidebar will also use the side to be fixed floating in there, while scrolling. In this case we can use this plugin as well.
Plug-in overview
Author: Caibaojian
Plug-in usage protocol: GNU general public LICENSE, free to use by both individuals and businesses.
The plug-in size is 2K (after compression), the plugin has been posted to the GitHub, you can go to the Project home page download source code and demo code, which has a JS file and six kinds of demo code.
GitHub Project Home Address
If you want to download JS directly, you can use this scrollfix.js (uncompressed 2.77k), scrollfix-min.js (2k after compression).
Package download Scrollfix.zip (contains JS and 6 demo code)Http://file.111cn.net/upload/2013/11/scrollfix.zip
Online Demo
| The code is as follows |
Copy Code |
var fix = $ (". Fix"), Fixtop = $ (". Fix-top"), Fixstarttop = $ (". Fix-starttop"), Fixstartbottom = $ (". Fix-startbottom"), fix Bottom = $ (". Fix-bottom"), Fixfooter = $ (". Fix-footer"); |
The first: The default scrolling to the beginning of the fixed: Fix.scrollfix ();
The second: rolling to the distance here at the top of 20 pixel start fixed: Fixtop.scrollfix ({distancetop:20});
Third: Scroll to a label #starttop Head Start fixed: Fixstarttop.scrollfix ({starttop: "#startTop"});
Fourth: Scroll to the end of a label #startbottom to start fixing: Fixstartbottom.scrollfix ({startbottom: "#startBottom"});
Fifth: Scrolling stop at the bottom 300 pixels: Fixbottom.scrollfix ({endpos:300});
Sixth: Scroll to stop at the bottom #fixfooter position: Fixfooter.scrollfix ({endpos: "#fixFooter"});
Parameter detailed
| Parameter name |
Parameter values |
Parameter action |
| Starttop |
Null |
Start fixing the top of the jquery object |
| Startbottom |
Null |
Start a fixed jquery object at the end, with two parameters set, the default back parameter takes effect |
| DistanceTop |
0/null |
Value, the height from the top, can be a height or jquery object |
| Endpos |
null/0 |
The height of the distance from the bottom can be a height or jquery object |
If you have improvements and comments on this plugin, please feel free to give me feedback, or you can send me a message in GitHub at pull. Thank you very much for your use, Scrollfix is growing up. Your comments and forwarding are all for our support.
Imitation Baidu paste head fixed not with the scroll bar scrolling effect
| The code is as follows |
Copy Code |
| <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/> <title> Navigation Fixed </title> <script src= "/ajaxjs/jquery1.3.2.js" language= "JavaScript" type= "Text/javascript" ></script> <script> $ (function () { $ (window). Scroll (function () { $ ("Body"). CSS ({"Background-position": "Center" +$ (window). scrolltop () + ""}); if ($ (window). scrolltop () >=250) { $ (". Nav"). AddClass ("Fixednav"); }else{ $ (". Nav"). Removeclass ("Fixednav"); } }); }); </script> <style> *{ margin:0px; padding:0px; } div.nav{ Background: #000000; height:57px; line-height:57px; Color: #ffffff; Text-align:center; font-family: "Microsoft Ya Black", "bold"; font-size:30px; } div.fixednav{ position:fixed; top:0px; left:0px; width:100%; z-index:100000; _position:absolute; _top:expression (eval (document.documentElement.scrollTop)); } </style> <body> <div class= "header" style= "background: #CCCC00; height:250px;" ></div> <div class= "NAV" > <p> Navigation Fixed </p> </div> <div class= "Content" style= "background: #0099FF; height:2000px; " ></div> </body>
|
Finally everyone to download the source bar: Http://file.111cn.net/upload/2013/11/scrollfix.zip