Difference between revisions of "Template:HZAU-China/Javascript/floathzaujs"
Wyb michael (Talk | contribs) |
Wyb michael (Talk | contribs) |
||
Line 8: | Line 8: | ||
element.css({ | element.css({ | ||
position: "fixed", | position: "fixed", | ||
− | top: | + | 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();