<script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script> <script> $.fn.smartFloat=function(x){ var element=$(this); var thetop=element.position().top; var pos=element.css('position'); var wid=element.css('width'); var offsetleft=element.offset().left; var offsettop=element.offset().top; $(window).scroll(function(){ var scrolls=$(this).scrollTop(); if(scrolls>thetop+x){ element.css({position: 'fixed',top: 0,width: wid}); element.offset({top:null,left:offsetleft}); }else{ element.css({position: pos,top: thetop,width: wid}); } }); }; $('#tag_cloud-2').smartFloat(); </script>