js返回点击事件返回页面顶部

 <div class="top"></div>

 .top {
                position: fixed;
                right: 0;
                bottom: 20px;
                width: 40px;
                height: 40px;
                line-height: 40px;
                text-align: center;
                background-color: #fff;
                color: #ed3932;
                font-size: 24px;
                cursor: pointer;
            }
 
   // to top
        $(".top").hide();//隐藏
        $(window).scroll(function () {
            if ($(window).scrollTop() > 150) {
                $(".top").fadeIn();//淡入效果
            } else {
                $(".top").fadeOut();//淡出效果
            }
        })
        $(".top").click(function () {
            $("html,body").animate({ scrollTop: 0 }, 400);
        })
posted @   诗人zoro  阅读(197)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示