<!-- in css: --> <style> #up-btn { position: fixed; bottom: 20px; right: 20px; z-index: 15; cursor: pointer; transition: all .3s; } img[src$=".svg"]{ width:48px } </style> <!-- in html: --> <div class="btn-hide" data-id="" data-element_type="widget" id="up-btn" data-settings="" alt="scroll to top"> <img width="40" height="55" src="https://aspx.co.il/wp-content/uploads/2023/04/arrowup.svg" class="" alt="arrowup" /> </div> <!-- in js: --> <script src="https://code.jquery.com/jquery-3.7.1.min.js" crossorigin="anonymous"></script> <script type="text/javascript" async> jQuery(document).ready(function($){ //Check to see if the window is top if more then 500px from top display button $(window).scroll(function(){ if ($(this).scrollTop() > 500) { $('#up-btn').fadeIn(300,'linear').removeClass('btn-hide'); } else { $('#up-btn').fadeOut(200).hide('slow').addClass('btn-hide'); } }); //Click event to scroll to top $('#up-btn').click(function(){ $('html, body').animate({scrollTop : 0},800); $(this).addClass('btn-hide'); return false; }); </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