- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Scroll To Top</title>
- <script src1="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
- <style>
- .backtop {
- background: url(http://www.w3cschool.cc/wp-content/themes/w3cschool.cc/assets/img/backtotop.png) no-repeat center center;
- bottom: 20px;
- cursor: pointer;
- display: none;
- height: 70px;
- position: fixed;
- right: 20px;
- text-indent: -9999px;
- width: 70px;
- z-index: 100;
- }
- </style>
- </head>
- <body style="height:5000px;">
- <a class="backtop" href="javascript:void" style="display: none;"></a>
- <script>
- var h = $(window).height();
- $(window).scroll(function () {
- if($(window).scrollTop()>=h*3) {
- $(".backtop").fadeIn();
- }else {
- $(".backtop").fadeOut();
- }
- });
- $(".backtop").click(function(event){
- $('html,body').animate({scrollTop:0}, 500);
- return false;
- });
- </script>
- </body>
- </html>
- //该片段来自于http://www.codesnippet.cn/detail/1206201512853.html
来源: http://www.codesnippet.cn/detail/1206201512853.html