Tue, October 27, 2020, 21:08:21
 
Home · Latest · Trends  /  HTML, XML
1

jQuery - Scroll to the top of the page button

Scroll to the top of the page button with jQuery
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Untitled</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
    <style>
        body,html{
        height: 200%;
        }
        #gototop{
        display: none;
        font-size: 38px;
        background: rgba(97, 123, 199, 0.72);
        position: fixed;
        bottom: 50px;
        right: 50px;
        width: 70px;
        height: 70px;
        line-height: 60px;
        text-align: center;
        color: #fff;
        cursor:pointer;
    }
    </style>
</head>
<body>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <a id="gototop"><i class="fa fa-chevron-up"></i></a>
    <script>
        $(window).scroll(function() {
          var offset = $("body").offset().top + 600;
          if ($(window).scrollTop() >= offset) {
              $("#gototop").show("slow");
              }else{
              $("#gototop").hide("slow");
           }
        });
        $("#gototop").click(function(){
                  $('html, body').animate({ scrollTop: 0 }, 'slow');
        });
    </script>
</body>
</html>
rated 1 times [  1] [ 0]  / comments: 0 / hits: 1311  / 3 years ago, wed, aug 30, 2017, 05:56:41
More From » HTML, XML
 

Comments

There are no comments for this Snippet yet
Username
 
Your Comment
 
Share
Snippets
MySQL error when update default value for DATETIME
3 years ago, sun, aug 6, 2017
3 years ago, sun, aug 6, 2017
TinyMCE v 4 change default font style, font family, color...
3 years ago, tue, aug 22, 2017
CSS change bootstrap 4 tooltip color
3 years ago, tue, aug 22, 2017
Posted
bigjoe

bigjoe

Member since Aug 6, 2017
Total Code Snippets: 5
Total Comments: 0
Location: n/a
Following
User not following anyone yet.