1 <body> 2 <div style="height: 2000px;"></div> 3 <a href="#" id="backTop" style="display: none;position: fixed;bottom: 0;right: 0;">回到顶部</a> 4 <script> 5 window.addEventListener('scroll', function () { 6 var backTop = document.getElementById('backTop'); 7 if (document.body.scrollTop > 200) { 8 backTop.style.display = 'block'; 9 } else { 10 backTop.style.display = 'none'; 11 } 12 }) 13 </script> 14 </body>