0

I hava a downlink on my homepage that moves the page down when the user clicks. I have tried to get this to alter to a back to top link as soon as the user scrolls 10 pixels from the top but cannot get it to work. Does anyone see where i am going wrong. One other thing that isn't working is the smooth scroll jQuery.

HEAD

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript" src="JQuery/jquery.js"></script>
<script type="text/javascript" src="JQuery/html5lightbox.js"></script>
<script type="text/javascript" src="JQuery/counter.js"></script>
<script type="text/javascript" src="JQuery/smoothscroll.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script type="text/javascript" src="JQuery/script.js"></script>

HTML

<div class="down-link"><a href="#about" id="w-downlink" class="smoothscroll"><i class="ss-navigatedown"></i></a></div>

CSS

.down-link {
    width:100%;
    height:50px;    
}

#w-downlink i {
    line-height: 42px;
    font-size: 24px;
    color: #fff;
    display: block;
    width: 24px;
    margin: 0 auto;
    margin-top:10px;
}

#w-downlink {
    height: 60px;
    width: 60px;
    background-color: #191919;
    background-color: rgba(20, 20, 20, 0.4);
    position:absolute;
    bottom:0;
    margin-bottom:30px;
    right:0;
    margin-right:20px;
    cursor: pointer;
    -webkit-transform: translate3d(0, 0, 0);
    opacity: 1;
}

.w-downlink:hover {
    height: 60px;
    width: 60px;
    background-color: #191919;
    background-color: rgba(20, 20, 20, 0.4);
    position:absolute;
    bottom:0;
    margin-bottom:30px;
    right:0;
    margin-right:20px;
     cursor: pointer;
    -webkit-transform: translate3d(0, 0, 0);
    opacity: 0.5;
}

jQuery used is the smooth scroll plug in.

 $('.w-downlinkn').click(function() {
    $('html, body').animate({ scroll: 250 });
});

thanks in advance for your support.

iamdanmorris
  • 307
  • 2
  • 6
  • 13
  • Please show the jQuery you are using to scroll down and the head section showing the following scripts being included: jQuery, smoothScroll, and your custom jQuery. – depiction Aug 27 '16 at 12:58

1 Answers1

0

To Answer your smooth scroll question:

You need to use "scrollTop" instead of "scroll":

$("html, body").animate({ scrollTop: "300px" });

See: Is it possible to animate scrollTop with jQuery?

To change the scroll link:

$(window).scroll(function() {
  var scrollDownLink = $('#w-downlink');
  if ($(window).scrollTop() < 10) {
    scrollDownLink.attr('href', '#about');
    scrollDownLink.find('i').removeClass('ss-navigateup').addClass('ss-navigatedown');
  } else {
    scrollDownLink.attr('href', '#top-anchor');
    scrollDownLink.find('i').removeClass('ss-navigatedown').addClass('ss-navigateup');
  }
}

For this you need to add a empty anchor directly as the first element in the body:

<body>
    <a id="top-anchor"></a>
    ...
</body>
Simon Jentsch
  • 707
  • 5
  • 10