Posted in Javascript onAugust 23, 2011
HTML代码:
<div class="float" id="float"> 我是个腼腆羞涩的浮动层... </div>
JS代码:
var $smartFloat = function(elements) { var position = function(element) { var top = element.getPosition().y, pos = element.getStyle("position"); window.addEvent("scroll", function() { var scrolls = this.getScroll().y; if (scrolls > top) { if (window.XMLHttpRequest) { element.setStyles({ position: "fixed", top: 0 }); } else { element.setStyles({ top: scrolls }); } }else { element.setStyles({ position: "absolute", top: top }); } }); }; if ($type(elements) === "array") { return elements.each(function(items) { position(items); }); } else if ($type(elements) === "element") { position(elements); } }; //绑定 $smartFloat($("float"));
MooTools 页面滚动浮动层智能定位实现代码
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@