Home > Article > Web Front-end > Usage example of jquery control that can float an object_jquery
The example in this article describes a jquery control that can float an object. Share it with everyone for your reference. The details are as follows:
js code is as follows:
(function($){ $.fn.scrolltip = function(){ $(this).each( function() { var obj = $(this); var objtop = obj.position().top; $(window).scroll(function(){ obj.css({ top:$(window).scrollTop()+objtop, position:'absolute' }); }); }); } })(jQuery);
The html code is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <script type="text/javascript" src="lib/jquery/jquery-1.3.2.js"></script> <script type="text/javascript" src="js/tip.js"></script> </script> <title>JQuery</title> </head> <body><div style="height:300px;background:#eee"><span id="colspon"></span></div> <br/> <br/> <br/> <div id="float" style="width:744px;height:34px;border:1px solid #C0DBF8;"></div> <div style="height:1000px;background:#eee"></div> </body> </html>
I hope this article will be helpful to everyone’s jquery programming design.