基于jQuery的回到页面顶部按钮可以通过以下代码实现:,,``html,,,,,,Back to Top Button,, .back-to-top {, display: none;, position: fixed;, bottom: 20px;, right: 20px;, background-color: #f1f1f1;, padding: 10px;, border-radius: 4px;, cursor: pointer;, },,,,,,,,Back to Top,,, $(document).ready(function() {, $(window).scroll(function() {, if ($(this).scrollTop() > 100) {, $('.back-to-top').fadeIn();, } else {, $('.back-to-top').fadeOut();, }, });,, $('.back-to-top').click(function() {, $('html, body').animate({scrollTop: 0}, 500);, return false;, });, });,,,,``,,这段代码创建了一个基于jQuery的回到页面顶部按钮。当用户向下滚动超过100像素时,按钮会显示出来。点击按钮后,页面会平滑地滚动到顶部。基于jQuery的回到页面顶部按钮
实现步骤
1、引入jQuery库:确保你的网页已经引入了jQuery库,可以通过以下方式引入:
```html
<script src="https://code.jquery.com/jquery-3.6.0.min.js">script>
```
2、创建HTML元素:在你想要显示“回到顶部”按钮的地方,添加一个HTML元素,例如一个