I built a featured tabbing system (4 tabs) with jquery. It works manually but I want to make it loop automatically, i.g. every 5 seconds. I can trigger each tab with the click even but I don't know how to go back to the beginning from 1st tab once it reach the last tab.
The coding too long to past here, so I have made a jsfiddle link to it: http://jsfiddle.net/ZSPX3/
I just wanna iterate through each tab and click them each, then start from the beginning of the tab again, as in I want an infinite slideshow. But I'm stuck...
I don't want any plugins, I wanna learn how to do this with my own hand, please.
Many thanks
The key part here is to check the index of the currently-on tab and see if there's any tabs beyond it. If not, revert to the first tab. So:
HTML
CSS
JS (jQuery assumed)
We compare the (zero-indexed) index of the currently-on tab with the total number of tabs (-1, to account for the zero-indexing). If the former is lower than the latter, there's still some tabs to go; if not, i.e. they're equal, we've reached the end - go back to the start.
Hope this helps.
Here's some code you can use:
jQuery:
Updated jsFiddle example.