×

jQuery页面滚动浮动层智能定位实例代码

作者:Terry2017.02.12来源:Web前端之家浏览:8443评论:0
关键词:JQueryJS
HTML代码:
复制代码 代码如下:

<div class="float" id="float">
我是个腼腆羞涩的浮动层...
</div>

JS代码:
复制代码 代码如下:

$.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: 0
});
} else {
element.css({
top: scrolls
});
}
}else {
element.css({
position: "absolute",
top: top
});
}
});
};
return $(this).each(function() {
position($(this));
});
};
//绑定
$("#float").smartFloat();

您的支持是我们创作的动力!
温馨提示:本文作者系Terry ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://jiangweishan.com/article/svg1486828800656.html

网友评论文明上网理性发言已有0人参与

发表评论: