【www.gdgbn.com--js教程】
js页面滚动时层智能浮动定位实现
<script type="text/网页特效" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
我是个腼腆羞涩的浮动层...
<script>
$.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));
});
};//调用很简单,直接一行代码就ok了,例如下面:
$("#float").smartfloat();
</script>