2

I have a slider on my site but unfortunately it doesn't have an auto mode.

Is it possible to write a function that simulates a link being clicked at certain time intervals so that the slide rotates?

Darren Cook
  • 661
  • 4
  • 14
  • 28

2 Answers2

2

There is a click function that does just that.

var link = $('#your-slider-link');
window.setInterval(function() {
  link.click();
}, 100); // every 100ms.
ide
  • 19,942
  • 5
  • 64
  • 106
  • actually, the .click() function in jquery only triggers the associated events, not the actual link itself. depending on how this slideshow works, it might not be through an event, but rather through the link href itself. – Jesse Cohen Feb 12 '11 at 20:43
  • Doesn't the click method not work in Firefox, Safari & Chrome? You might need to consider the following. http://stackoverflow.com/questions/1421584/how-can-i-simulate-a-click-to-an-anchor-ta – David Feb 12 '11 at 20:44
  • @David: That's `HTMLElement.click()` which is pretty much specific to IE. Per Jesse's point, there are actual DOM click events and then jQuery's click events. If the slideshow uses `addEventListener('click', ...)` then this jQuery approach won't work, and the link you provided would be a nice solution. – ide Feb 12 '11 at 20:49
  • So `$('#your-slider-link')` returns a object defined by jQuery, and not the actual HTMLElement? I didn't know that. – David Feb 12 '11 at 20:56
  • @David: Yes, `$()` returns a jQuery object, that's why `$('.ten-divs-have-this-class').hide()` and such things can work. – mu is too short Feb 13 '11 at 05:08
0

If understood it right, you could make use of Nivo Slider http://nivo.dev7studios.com/ or use one from this list http://webdesignledger.com/tutorials/13-super-useful-jquery-content-slider-scripts-and-tutorials or from this one http://webdesignfan.com/jquery-slider-tutorials-and-plugins/ or search for jquery slider on google, as I did. hehe :). I use Nivo and it is very good but search again for this I found many others. I am going to try some of them.

msmafra
  • 1,704
  • 3
  • 21
  • 34