*Help needed* Fade in 'Back to top' fixed bar when user scrolls then fade-out

Hi there,
I need some help. I’m trying to get my fixed footer-style back-to-top bar to fade-in once the user scrolls beyond a certain point, this is what i’ve got so far but it won’t work.
Any idea way.



//Check to see if the window is top if not then display button
if ($(this).scrollTop() > 100) {
} else {

<div id=“fixed-backtotop”>
<a class=“btt” href=“#” onclick=“return false;” onclick=“return false;” onmousedown=“resetScroller(‘header’);”>Back to Top</a>

To clarify, i have to scroll to the top of the page working, however i only want the div to appear once the user scrolls beyond say 100px.


Welcome to the forums :slight_smile:

At first glance, it seems that the fadeIn code is firing again and again when the user scrolls.

Try adding a check to see if the element is already visible, before attempting to fade it in:

  if ($(this).scrollTop() >= 100 && !$('#fixed-backtotop').is(":visible")) {
  } elsif ($(this).scrollTop() < 100 && $('#fixed-backtotop').is(":visible")){

If that doesn’t work (untested), please post a link to a page where I can see this not working.

I did a awesome one here http://www.websitecodetutorials.com/code/jquery-plugins/a-better-jquery-back-to-top-of-page.php

Thanks @PicnicTutorials & @Pullo,
I managed to get Picnictutorials solution working however, i would love your help with the code. I’m a complete javascript novice.
So the code i used integrated the scroll back to top, however i already have this sorted. So i’d like to remove that piece of code however i don’t know much about the syntax.

“$(function(){$(window).scroll(function(){if($(this).scrollTop()>100){$(”#fixed-backtotop").fadeIn(1000)}else{$(“#fixed-backtotop”).fadeOut(750)}})};$(“#fixed-backtotop”).click(function(){$(“html, body”).animate({scrollTop:0},600);return false})});"

i want to remove the
“$(”#fixed-backtotop").click(function(){$(“html, body”).animate({scrollTop:0},600);return false"

However i can’t get the syntax right, can anyone help ?


Like this?