简体   繁体   中英

How can I add automatic click functionality after 60second to button and perform that operation using javascript?

I tried solutions for similar asked questions before but they are not working for my purpose This is my button

 <a class="goto-next-slide overlay-button overlay-right" id="nxt">Next</a>    

this is my javascrit function which is performing click operation

function gotoNextSlide() {
goToSlide(getCurrentSlide().index() + 1);
 }

Now the event is happening only when I clicked the button but what should I do to perform operation when next button get clicked automatically after 60 seconds. this is my jquery where I am calling the gotoNextSlide() function.

function init() {
$("#nxt").click(gotoNextSlide);
}
$(document).ready(init);

how can I do it?

I tried by this method

<script>
    var tmp;
    function f1() {
        tmp = setTimeout("(gotoNextSlide)", 2000);
    }
    function callNext() {
        document.getElementById("nxt").click();
    }
</script>

Use setTimeout to queue goToNextSlide after 60 seconds. Whenever someone clicks "next" button or 60 seconds passed, clear the timeout, change the slide, and queue it again after 60 seconds.

var timer;

function gotoNextSlide() {
   timer && clearTimeout(timer);
   goToSlide(getCurrentSlide().index() + 1);
   timer = setTimeout(gotoNextSlide, 1000 * 60);
}

function init() {
  $("#nxt").click(gotoNextSlide);
  timer = setTimeout(gotoNextSlide, 1000 * 60);
}
$(document).ready(init);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM