Thu, September 23, 2021
 
https://devcodepro.comdevcodepro
X
Home · Latest · Trends
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: 1540  / 4 years ago, wed, aug 30, 17, 05:56:41
More From » HTML, XML
 

Comments

There are no comments for this Snippet yet
Only authorized users can post. Please sign in first, or register a free account
 
Share
Posted
bigjoe
Member since Aug 6, 2017
Total Code Snippets: 5
Total Comments: 0
Location: n/a
bigjoe snippets
4 years ago, sun, aug 6, 17, 5:31:35
comments: 0 / hits: 2713
SQL
4 years ago, sun, aug 6, 17, 5:14:06
comments: 0 / hits: 3350
SQL
4 years ago, tue, aug 22, 17, 7:46:43
comments: 0 / hits: 1880
4 years ago, tue, aug 22, 17, 6:12:46
comments: 1 / hits: 6748
CSS