Difference between revisions of "Template:HZAU-China/Javascript/floathzaujs"

 
Line 8: Line 8:
 
element.css({
 
element.css({
 
position: "fixed",
 
position: "fixed",
top: 20
+
top: 15
 
});
 
});
 
} else {
 
} else {

Latest revision as of 10:55, 18 September 2015

$.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: 15 }); } else { element.css({ top: scrolls }); } }else { element.css({ position: pos, top: top }); } }); }; return $(this).each(function() { position($(this)); }); };

//调用方法 //$("#fixed").smartFloat();