Auto Scroller for demos

Just an auto scroller if you want to demo a website.

by Augustus Yuan

HTML

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<h2 class="top">
Top
</h2>
<h2 class="bottom">
Bottom
</h2>

CSS

body {
  height: 1500px;
  background: red;
  position: relative;
}

h2 {
  color: white;
}

.top {
  position: absolute;
  top: 0px;
}

.bottom {
  position: absolute;
  bottom: 0px;
}

JavaScript

var scrollingUp = 0;

window.setInterval(scrollit, 3000);

function scrollit() {
    if(scrollingUp == 0) {
        $('body').delay(2000).animate({ scrollTop: $('body').scrollTop() + 500 }, 'slow');
    }
    
    if ($('body').scrollTop() + $('body').innerHeight() >= $('body')[0].scrollHeight) {
        scrollingUp = 1;      
        $('body').delay(2000).animate({ scrollTop: 0 }, 1000, function() {
            scrollingUp = 0;    
        });
    }
}

$('body').bind('scroll', function (e) {
});