thestudentlife/Manhattan-Project

View on GitHub
mainsite/templates/top_button_partial.html

Summary

Maintainability
Test Coverage
{% load staticfiles %}

<a id="top-btn" style="display: none" href="javascript:void(0)" onclick='scrollToTop();' class="btn btn-success">Back to Top</a>
<script src="{% static 'jquery-2.1.3.min.js' %}"></script>
<script>
    $(window).scroll(function () {
        if ($(window).scrollTop()>2000){
            $('#top-btn').show();
        }else{
            $('#top-btn').hide();
        }
    })

    var timeOut;
    function scrollToTop() {
      if (document.body.scrollTop != 0 || document.documentElement.scrollTop != 0){
        window.scrollBy(0, -80);
        timeOut=setTimeout('scrollToTop()', 10);
      } else {
          clearTimeout(timeOut);
      }
    }
</script>