點選按鈕返回頂部
阿新 • • 發佈:2022-02-19
<!-- 10置頂 -->
<div class="totop">
<img src="images/totop.png" />
</div>
<script>
$(function() {
$(window).scroll(function() {
var scroHei = $(window).scrollTop();//滾動的高度
if (scroHei > 400) {
$('.totop').fadeIn();
} else {
$('.totop').fadeOut();
}
})
/*點選返回頂部*/
$('.totop').click(function() {
$('body,html').animate({
scrollTop: 0
}, 600);
})
})
</script>
參考連結:https://www.bbsmax.com/A/MAzAk1ey59/