首页 > 语言 > JavaScript > 正文

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

2024-05-06 14:23:49
字体:
来源:转载
供稿:网友
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();
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选