美文网首页
jquery点击按钮回到顶部

jquery点击按钮回到顶部

作者: 困猫喵 | 来源:发表于2019-11-08 02:25 被阅读0次

    css部分:

    <style type="text/css">

    .container {

    width:980px;

    margin:0 auto;

    height:auto;

    min-height:100%;

    position:relative;

    }

    .content {

    height:2000px;

    border:1px solid red;

    }

    #goToTop {

    position:fixed;

    bottom:20px;

    right:10%;

    }

    #goToTop a {

    background:none repeat scroll 0 0 #336699;

    border:1px solid #CCCCCC;

    border-radius:3px;

    -webkit-border-radius:3px;

    color:#FF9966;

    font-size:14px;

    padding:5px;

    text-decoration:none;

    text-shadow:0 1px 0 #999;

    -webkit-text-shadow:0 1px 0 #999;

    }

    </style>


    html部分:

    <div class="container">

    <div class="header">我是头部</div>

    <div class="content">我是主内容,高度是2000px</div>

    <div class="footer">我是在最底部</div>

    <div id="goToTop"><a href="#">点我回到页面顶部</a></div>

    </div>


    js部分:

    <script type="text/javascript">

    $(document).ready(function(){

    $('#goToTop a').click(function(){

    $('html,body').animate({scrollTop:0},'slow');

    });

    });

    </script>

    相关文章

      网友评论

          本文标题:jquery点击按钮回到顶部

          本文链接:https://www.haomeiwen.com/subject/sjobbctx.html