引是jquery库
<script type="text/javascript" src="js/jquery.min.js"></script>
js
<script type="text/javascript">
$(function(){
$(window).scroll(function() {
if($(window).scrollTop() >= 100){
$('.actGotop').fadeIn(300);
}else{
$('.actGotop').fadeOut(300);
}
});
$('.actGotop').click(function(){
$('html,body').animate({scrollTop: '0px'}, 800);});
});
</script>html
<div class="actGotop"><a href="javascript:;" title="返回顶部"></a></div>
作者你有没有考虑这个问题 当鼠标多次单机返回顶部的按钮后 他会有一段时间一直在滚动条会一直向上运动
你应该加一个函数截流 就是当你鼠标点击时滚动条从底部运动到0位置的时间内返回顶部的按钮单击无效
回复