<div class="fixed-action-btn show-mobile-only"> <a class="btn-floating btn-large light-green" title="Back to Top" onclick="scrolltoTop()" id="scrollBtn"> <i class="material-icons">keyboard_arrow_up</i> </a> </div> <script> // When the user scrolls down 100px from the top of the document, show the button window.onscroll = function () { scrollFunction() }; function scrollFunction() { if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) { document.getElementById("scrollBtn").style.display = "inline-block"; } else { document.getElementById("scrollBtn").style.display = "none"; } } // When the user clicks on the button, scroll to the top of the document function scrolltoTop() { document.body.scrollTop = 0; // For Safari document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera } </script>
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter