0

When site is loaded I want to automatically press the down arrow key every few seconds without any user interactions. Any ideas to do this with JS or jQuery?

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339

2 Answers2

0

Try it with this snippet:

$(document).ready(() => {
  let e = $.Event("keyup");

  e.which = 40; // keycode for down arrow

  // Fire event every second
  setInterval(()=>{
    $(document).trigger(e);
  }, 1000);
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

It is possible with pure JavaScript Code too, but its quite a hassle.

MauriceNino
  • 6,214
  • 1
  • 23
  • 60
0

So I used onepage-scroll library (https://github.com/peachananr/onepage-scroll) for section scroll and here is answer of my question (now it works):

        if( $('.onepage-pagination li').length > 1 ){
        var steps = $('.onepage-pagination li').length;
        //console.log( 'steps', steps );

        var i = 2;
        var autoplay = setInterval(function(){}, 4000);
        autoplay = setInterval(function(){
            $('[data-index="'+i+'"]').click();
            //console.log( 'step click', i );
            if(i == 5){
                i = 1
            }else{
                i++
            }
        }, 7000);

        $(document).bind('mousewheel DOMMouseScroll touchstart', function(event) {
            clearInterval(autoplay);
            console.log( 'slide stopped');
        });
    } 

But if anyone have any other ideas I would like to see them just to know new features in case.

Thank you.