Auto-click every 10 seconds

Asked

Viewed 605 times

0

I have a Carousel on the site, and I want it to run every ten seconds, as if the visitor had clicked the button to effect this process.

This is the site http://www.clinicafelipemeletti.com.br/

Here is all the JS plugin (WP Carousel Posts) https://jsfiddle.net/felipestoker/c3dL9tzj/

And here, the inclusion I made in this JS

window.setTimeout(function(){
   document.getElementsByClassName("owl-dot").click();
}, 10000);

It’s not working. I wonder why.

2 answers

4

A suggestion: I Maybe it’s nice you take a look at the Bootstrap carousel, in case you don’t know it: Carousel with Bootstrap

Good, but if you need that way the functioning of the site, you can do the following:

var runCarousel = function (carousel, index, timeout) {
    window.setTimeout(function(){
    carousel[index].click();
    }, index*timeout);
}

This function will cause the selected carousel(Carousel) to "run" the carousel with the time difference (timeout) you want.

An example of using the function would be like this:

var carousel = document.getElementsByClassName("owl-dot");

for (var i = 0; i < carousel.length; i++) {
    runCarousel(carousel, i, 2000)
}

This will cause the carousel (with "Owl-dot" class buttons) to run every 2 seconds!

I hope I’ve helped,

Giulio~

  • Thank you so much for the Bootstrap tip. I won’t use it now, because this site wasn’t developed by me. That’s why I’m having trouble solving it. The code you gave me, will it work if I put it in this JS file? http://www.clinicafelipemeletti.com.br/wp-content/plugins/wp-posts-carousel/owl.carousel/owl.carousel.js?ver=2.0.0 If yes, where would be the ideal?

  • Felipe, this code is really big. It seems that there are even functions there that will turn the carousel... But considering that you only need the quick solution of the problem, I would put as an asynchronous function in infinite loop off the carousel. I believe this is not the best solution, but it will solve your problem quickly!

0

I’ve been taking a look at the site. If you’re working on the home page photo show:

jquery:

var slideNum = 0;
setInterval(function() {
   jQuery('a.nivo-control').removeClass('active');
   jQuery('a.nivo-control[rel="' +slideNum+ '"]').click();
   jQuery('a.nivo-control[rel="' +slideNum+ '"]').addClass('active');
   slideNum += 1;
   if(slideNum >= jQuery('a.nivo-control').length) {
       slideNum = 0;
   }
}, 10000);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.