[url]http://www.cnblogs.com/regedit/archive/2008/03/11/1100170.html[/url]
见第一个附件
存在问题:当放大或者缩小窗口时候,浮动不会变化。
只能浮动:[url]http://www.zhangxinxu.com/study/201011/smart-float-by-jquery.html[/url]
<div class="float" id="float">
我是个腼腆羞涩的浮动层...
</div>
见第一个附件
存在问题:当放大或者缩小窗口时候,浮动不会变化。
只能浮动:[url]http://www.zhangxinxu.com/study/201011/smart-float-by-jquery.html[/url]
<div class="float" id="float">
我是个腼腆羞涩的浮动层...
</div>
$.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();
本文介绍了一个使用jQuery实现的浮动层智能调整位置的方法。当浏览器窗口滚动时,该方法能够自动调整浮动层的位置,确保其始终可见。适用于各种浏览器环境。
2267

被折叠的 条评论
为什么被折叠?



