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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2020-05-13 我要评论
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();

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们