-1

Hello i want to make the scroll bar to auto scroll in my upcoming events and after some seconds it will scroll back to top again i want it to continuosly scrolling up and down in a slow pace. Can someone help me about this or give me some ideas? Don't have an idea. Im just starting to learn javascript.

here's a picture.

enter image description here

nethken
  • 1,072
  • 7
  • 24
  • 40

1 Answers1

1

you can use .scrollTop() function in jquery jQuery Scrolltop and setTimeout for timer

html

<p><button id="scroll">scrollTop()</button></p>
<div id="test"></div>

css

#test {
    width: 100px;
    height: 100px;
    position: relative;
    top: 1000px;
    background: green;
}

javascript

$('#scroll').click(function() {
    $('html,body').animate({
        scrollTop: $('#test').css('top')
    }, 800, function() {
        setTimeout(function(){
          $('html, body').animate({
              scrollTop: 0
          }, 800);
        }, 2000);
    });
});

i try to create simple example in jsFiddle Here

Pajar Fathurrahman
  • 991
  • 1
  • 9
  • 19