随页面滚动固定显示
#div1{
background-color: #0062CC;
overflow: hidden;
z-index: 9999;//防止被遮挡调到最大值
position: fixed;
width: 100%;
height: 5%;
right:0px;//距离左边距离右边同理
top: 0px;//距离顶部距离
text-align: center;
}
<div id="div1">
</div>
随页面滚动浮动显示
<div id="fudong" style="width:90%; height:5%; position: absolute; right: 0px; top: 0px;z-index:9999;">
</div>
$(function() {
var timer, scrollTop, sideDiv = $('#fudong').appendTo('body');
$(window).scroll(function() {
timer && clearTimeout(timer);
scrollTop = $(this).scrollTop();
timer = setTimeout(function() {
sideDiv.animate({
top: scrollTop
}, 10);
}, 10);
});
});