Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
var offset = 700;
var speed = 250;
var duration = 500;
if ($(this).scrollTop() < offset) {
$('.topbutton') .fadeOut(duration);
} else {
$('.topbutton') .fadeIn(duration);
$('.topbutton').on('click', function(){
$('html, body').animate({scrollTop:0}, speed);
return false;
//Text to be placed for icon makrup (FontAwesome Required)
<a href="#" class="topbutton"><i class="fa fa-chevron-circle-up"></i></a>
Copy link

akramulhasan commented Aug 21, 2022

This script (along with some other code in functions.php) will add Scroll to top feature in a WordPress site

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment