1. 程式人生 > 其它 >點選按鈕返回頂部

點選按鈕返回頂部

<!-- 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/