jquery实现简单的回到顶部

来源:互联网 发布:mysql删除表数据 编辑:程序博客网 时间:2024/05/16 13:58
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js"></script>
    <style>
        .box1{
            width:35px;
            height:35px;
            background-color: #00b3ee;
            text-align: center;
            line-height: 35px;
            font-size: 36px;
            font-weight: bold;
            text-decoration: none;
            display: block;
            position: fixed;
            bottom:30px;
            right:30px;
            display: none;
        }
        .box1:hover{
            background-color: #00B83F;
        }
    </style>
</head>
<body>
<div style="background:#ff9900;height:100px;"></div>
<div style="background:#ccc;height:1200px;"></div>
<a href="javascript:(0);" class="box1">↑</a>


<script>
    $(function(){
$(window).scroll(function(){
var t = $(this).scrollTop();
if(t>100){
$(".box1").fadeIn();
}else{
$(".box1").fadeOut();
}
});
$(".box1").on("click",function(){
$("body,html").animate({scrollTop:0},300);
});
    })
</script>
</body>
</html>
0 0