我想修复上一次按钮和下一次按钮的位置 如何使用jquery scroll事件?
<div class="content">
<div class="items">
dfjdslkfjdls;ajfdls;jkfa;fd;lsjfl;dsasjfl;akjf
<div class="prev button">prev</div>
<div class="next button">next</div>
</div>
// jquery的
$(window).bind('scroll', function() {
if ($(window).scrollTop() > 50) {
$('.button').addClass('fixed'); // within contnet
}
else {
$('.button').removeClass('fixed'); // within content
}
});
请参阅jfiddle http://jsfiddle.net/kisspa/deN3g/2/
答案 0 :(得分:2)
测试我的代码
function loadswitharrow(){
$(window).bind('scroll', function() {
if ($(window).scrollTop() >= 0) {
$('.button').addClass('fixed');
}
else {
$('.button').removeClass('fixed');
}
});
}
CSS
.fixed{position:fixed;}
.prevbutton{left:-3%;}
.nextbutton{right:-3%;}
.fixed.nextbutton{right:17%;}
.fixed.prevbutton{left:17%;}