Advertisement
Guest User

Untitled

a guest
Sep 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1. <script>
  2.         // When the user scrolls down 20px from the top of the document, show the button
  3.         window.onscroll = function() {scrollFunction()};
  4.  
  5.         function scrollFunction() {
  6.             if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
  7.                 document.getElementById("myBtn").style.display = "block";
  8.             } else {
  9.                 document.getElementById("myBtn").style.display = "none";
  10.             }
  11.         }
  12.  
  13.         // When the user clicks on the button, scroll to the top of the document
  14.         function topFunction() {
  15.             document.body.scrollTop = 0;
  16.             document.documentElement.scrollTop = 0;
  17.         }
  18.         </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement