您好!欢迎来到北极熊

北极熊

热门搜索: 任正非传    神雕侠侣    红楼梦   

HTML,CSS,JS 一键回到网页顶部

分类:技术交流 时间:2021-02-28 20:55 浏览:551
概述
Html代码1<div id="gotop"><a class="gotop"></a></div>CSS代码12345678910111213141516171819202122232425.gotop {    cursor: pointer;    position
内容

Html代码

1
<div id="gotop"><a class="gotop"></a></div>


CSS代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
.gotop {
    cursor: pointer;
    position: fixed;
    right: 25px;
    bottom: 25px;
    z-index: 99999;
    display: block;
    width: 50px;
    height: 50px;
    background: url(../images/backtop.png) no-repeat 0 0;
    opacity: 0.5;
    filter: alpha(opacity=50);
 
    /*动画效果*/
    outline: none;
    transition: all 0.30s ease-in-out;
    -webkit-transition: all 0.30s ease-in-out;
    -moz-transition: all 0.30s ease-in-out;
    -o-transition: all 0.30s ease-in-out;
    -ms-transition: all 0.30s ease-in-out;
}
 
    .gotop:hover {
        background: url(../images/backtop.png) no-repeat 0 -52px;
    }

图片backtop.png


JS代码

1
2
3
4
5
6
7
8
9
10
11
12
13
$("#gotop").hide();
$(window).scroll(function () {
    if ($(window).scrollTop() > 100) {
        $("#gotop").fadeIn()
    } else {
        $("#gotop").fadeOut()
    }
});
$("#gotop").click(function () {
    $('html,body').animate({
        'scrollTop': 0
    }, 500)
});


评论
资讯正文页右侧广告
联系我们
电话:18936411277
邮箱:1044412291@qq.com
时间:09:00 - 19:00
公众号:北格软件
底部广告