Dear friends, you may have encountered positioning problems, especially those on your blog or Weibo. As a result, our product staff will have that effect during planning ,,, however, we need to implement, implement, and so on ..... No way. Who makes us a city attacker:
As shown in the following figure, when the scroll bar is pulled down, the Black Block TOP is 0, and the display is fixed:
The Code is as follows:Copy codeThe Code is as follows: <! DOCTYPE html>
<Html>
<Head>
<Title> jQuery implements intelligent floating location at the Page scrolling time layer </title>
<Meta name = "description" content = ""/>
<Script type = "text/javascript" src = "http://jt.875.cn/js/jquery.js"> </script>
<Style type = "text/css">
* {Margin: 0; padding: 0 ;}
. Top {height: 100px; background: # ccc; text-align: center; line-height: 100px; font-size: 40px ;}
Body {font: 12px/1.8 Arial; color: #666; height: 2000px ;}
. Float {width: 200px; height: 200px; border: 1px solid # ffecb0; background-color: #000; position: absolute; right: 10px; top: 150px ;}
</Style>
</Head>
<Body>
<Div class = "top"> navigation, navigation, and navigation </div>
<Div class = "float" id = "float"> </div>
<Script type = "text/javascript">
$. Fn. smartFloat = function (){
Var position = function (element ){
Var top = element. position (). top, pos = element.css ("position ");
$ (Window). scroll (function (){
Var scrolls = $ (this). scrollTop ();
If (scrolls> top ){
If (window. XMLHttpRequest ){
Element.css ({
Position: "fixed ",
Top: 0
});
} Else {
Element.css ({
Top: scrolls
});
}
} Else {
Element.css ({
Position: pos,
Top: top
});
}
});
};
Return $ (this). each (function (){
Position ($ (this ));
});
};
// Bind
$ ("# Float"). smartFloat ();
</Script>
</Div>
</Body>
</Html>