2、監聽滾動條事件,超過某個高度點擊圖片,將滾動條置頂0,就能跳回頂部了
<div id="Gotop" class="gotop">Go</div>
css:
.gotop{ position:fixed; bottom:20px; right:20px; display:none; width:50px; height:50px; line-height:50px;....}
$(function(){
$(window).scroll(function() {
if($(window).scrollTop() >= 100){
$('.Gotop').fadeIn(300);//滾動條超出100出現
}else{
$('.Gotop').fadeOut(300); //否則隱藏
}
});
$('.Gotop').click(function(){$('html,body').animate({scrollTop: '0px'}, 800);});//點擊滾動到頂部
});