Difference between revisions of "Template:HZAU-China/Javascript/floathzaujs"
Wyb michael (Talk | contribs) (Created page with "$.fn.smartFloat = function() { var position = function(element) { var top = element.position().top, pos = element.css("position"); $(window).scroll(function() { var sc...") |
Wyb michael (Talk | contribs) |
||
Line 8: | Line 8: | ||
element.css({ | element.css({ | ||
position: "fixed", | position: "fixed", | ||
− | top: | + | top: 20px |
}); | }); | ||
} else { | } else { |
Revision as of 10:54, 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: 20px }); } else { element.css({ top: scrolls }); } }else { element.css({ position: pos, top: top }); } }); }; return $(this).each(function() { position($(this)); }); };
//调用方法 //$("#fixed").smartFloat();