There are huge and lengthy jQuery scroll to top scripts are available throughout the web. But today we will learn to make an appearing scroll to top button with minimal jQ and CSS.
Initially, the scroll to top button will be hidden but as soon as the user will scroll down, the button will appear.
Open your footer template and add the following code at the very beginning:
and at the end before two close </div> tags:
Save your footer template. Open global.css and add at the end:
Now upload this up button in your theme image directory:
Remember to include jQ library in MyBB if it is already not. In headerinclude:
Enjoy scrolling back to top ...
Initially, the scroll to top button will be hidden but as soon as the user will scroll down, the button will appear.
Open your footer template and add the following code at the very beginning:
<script type="text/javascript">
jQuery.noConflict();
jQuery(function($) {
$("#backtop").hide();
$(window).scroll(function () {
if ($(this).scrollTop() > 400) {
$('#backtop').fadeIn(200);
} else {
$('#backtop').fadeOut(200);
}
});
$('.go-top').click(function () {
$('html,body').animate({
scrollTop: 0
}, 1000);
return false;
});
});
</script>
and at the end before two close </div> tags:
<div id='backtop'>
<a class='go-top' href='#top' title='Back to Top'><img src="{$theme['imgdir']}/top.png" /></a>
</div>
Save your footer template. Open global.css and add at the end:
#backtop {
position: fixed;
bottom: 50px;
right: 10px;
margin: 0;
padding: 0;
width: 36px;
height: 36px;
z-index: 100;
}
Now upload this up button in your theme image directory:
Remember to include jQ library in MyBB if it is already not. In headerinclude:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
Enjoy scrolling back to top ...