jQuery返回顶部

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/jquery-3.6.0.js"></script>
    <style>
        #gotop{
            width:40px;
            height:40px;
            background-color: gray;
            color:white;
            text-align:center;
            line-height:40px;
            position:fixed;
            right:20px;
            top:300px;
            cursor: pointer;
        }
        body{
            height:3000px;
        }
    </style>

    <script>
        $(function(){
            $("#gotop").click(function(){
                // 瞬间回到顶部
                $("html").scrollTop(0);
            })
        })
    </script>

</head>
<body>
    <div id="gotop">顶部</div>
</body>
</html>

 

 

 

 

 

posted @ 2021-04-20 16:08  Hhhr  阅读(27)  评论(0编辑  收藏  举报