Home  >  Article  >  Web Front-end  >  MooTools 页面滚动浮动层智能定位实现代码_Mootools

MooTools 页面滚动浮动层智能定位实现代码_Mootools

WBOY
WBOYOriginal
2016-05-16 18:03:06858browse

HTML代码:

复制代码 代码如下:


我是个腼腆羞涩的浮动层...


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"));
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn