Appearing Scroll to Top
#1
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:

Code:
<script type="text/javascript">
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:

Code:
<div id='backtop'>
    <a class='go-top' href='#top' title='Back to Top'><img src="BUTTON IMAGE" /></a>
</div>
Remember to change the Button Image to your needs. You may use this one as a quick paste:
[Image: OETNh.png]

Save your footer template. Open global.css and add at the end:

Code:
#backtop {
    position: fixed;
    bottom: 50px;
    right: 10px;
    margin: 0;
    padding: 0;
    width: 36px;
    height: 36px;
    z-index: 100;
}

Remember to include jQ library in MyBB if it is already not. In headerinclude:

Code:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
jQuery.noConflict();
</script>

Enjoy scrolling back to top ... Grin
Reply
#2
This is a cool code. I find myself scrolling to the top often, even though there is a scroll to top button embedded in each post. I just forget that it is there. This popping up will be an easy reminder. I had even contemplated putting nav links above the footer just to avoid scrolling...lol
Reply
#3
(08-04-2013, 07:52 PM)effone Wrote: Remember to include jQ library in MyBB if it is already not. In headerinclude:

Code:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
jQuery.noConflict();
</script>

Enjoy scrolling back to top ...  Grin

This is pretty cool stuff. BTW, I don't know where the headerinclude is. I'm still new to managing forums. Can you or somebody show me where to find it?
euan likes this post
Reply
#4
(16-11-2017, 06:45 PM)albano Wrote:
(08-04-2013, 07:52 PM)effone Wrote: Remember to include jQ library in MyBB if it is already not. In headerinclude:

Code:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
jQuery.noConflict();
</script>

Enjoy scrolling back to top ...  Grin

This is pretty cool stuff. BTW, I don't know where the headerinclude is. I'm still new to managing forums. Can you or somebody show me where to find it?

ACP > Templates & Style > Templates (left sidebar) > *YOUR THEME* > Ungrouped Templates > headerinclude
Reply