screen_rotation
Copied to Clipboard
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap demo</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXuppvnDJzQIu9" crossorigin="anonymous"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css" integrity="sha512-z3gLpd7yknf1YoNbCzqRKc4qyor8gaKU1qmn+CShxbuBusANI9QpRohGBreCFkKxLhei6S9CQXFEbbKuqLg0DA==" crossorigin="anonymous" referrerpolicy="no-referrer" /> <style> /* Custom CSS for the button */ #scrollToTopBtn { display: none; position: fixed; bottom: 20px; right: 30px; } </style> </head> <body> <div class="container p-3 shadow-sm"> <div style="height: 2000px;"> <h1>Bootstrap Scroll to Top of Page using Javascript</h1> <p>Scroll down to see the Scroll to Top button.</p> </div> <!-- Scroll to Top Button --> <button id="scrollToTopBtn" class="btn btn-primary" title="Go to top"> <i class="fas fa-arrow-up"></i> <!-- Font Awesome icon for "up" --> </button> </div> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js" integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/js/bootstrap.min.js" integrity="sha384-Rx+T1VzGupg4BHQYs2gCW9It+akI2MM/mndMCy36UVfodzcJcF0GGLxZIzObiEfa" crossorigin="anonymous"></script> <script> // Get the button element var scrollToTopBtn = document.getElementById("scrollToTopBtn"); // When the user scrolls down 20px from the top of the document, show the button window.onscroll = function () { if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) { scrollToTopBtn.style.display = "block"; } else { scrollToTopBtn.style.display = "none"; } }; // When the user clicks on the button, scroll to the top of the document scrollToTopBtn.onclick = function () { document.body.scrollTop = 0; // For Safari document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE, and Opera }; </script> </body> </html>