MooTools 页面滚动浮动层智能定位实现代码
HTML代码:
JS代码:
代码如下:
<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"));
相关推荐
aSuncat 2020-05-10
lcqin 2020-08-11
yaodilu 2020-08-03
lanzhusiyu 2020-07-18
小仙儿 2020-06-25
xiaohuli 2020-06-11
CaiKanXP 2020-06-09
songfens 2020-06-08
CSSEIKOCS 2020-05-19
Phoebe的学习天地 2020-05-09
nicepainkiller 2020-05-05
amwayy 2020-05-01
AlisaClass 2020-04-14
coulder 2020-04-08
wangjie 2020-02-26
xiaohuli 2020-02-23
福叔 2020-02-16