The example of this article is about the method of the suspension effect of jquery when the page elements are simply implemented. Share to everyone for your reference, specific as follows:
One, JS Code:
<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 $ (a). each (function () {
position ($ (this));
});
Bind
$ ("#float"). Smartfloat ();
</script>
Second, Html Code:
<div class= "float" id= "float" style= "border:1px solid #e0e0e0; padding:10px; " >
I was on top of the suspension zone </div>
<br/>
<br/>
<br
/> <br/> <br/ >
<br/>
<br/>
<br/>
<br/> <br/> <br/> <br/>
<br/>
<br/> <br/> <br/> <br/> <br
/ >
<br/>
<br/>
<br/>
<br/> <br/>
More interested readers of jquery-related content can view the site topics: "jquery common Plug-ins and Usage summary", "jquery common Classic Effects Summary", "jquery form operation Tips", "jquery operations JSON data tips," " jquery extension Techniques Summary, jquery drag-and-drop effects and tips summary, jquery table (table) Operation tips Summary, "jquery Ajax Usage Summary", "jquery animation and special effects usage Summary" and "jquery Selector usage Summary"
I hope this article will help you with the jquery program design.