Advertisement
Socialking

Untitled

Feb 18th, 2022
2,383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.89 KB | None | 0 0
  1. /**
  2.  *  Automatically slider slider button
  3.  */
  4.  
  5. // cache a reference to the tabs
  6. var tabContainer = $('#tabs');
  7. var tabs = $('#tabs li');
  8.  
  9. // on click to tab, turn it on, and turn previously-on tab off
  10. tabs.click(function() {
  11.       $(this).addClass('on').siblings('.on').removeClass('on');
  12. });
  13.  
  14. // auto-rotate every 5 seconds
  15. var slideInterval;
  16.  
  17. function initiateSlideInterval() {
  18.       slideInterval = setInterval(function() {
  19.  
  20.             // get currently-on tab
  21.             var onTab = tabs.filter('.on');
  22.  
  23.             // click either next tab, if exists, else first one
  24.             var nextTab = onTab.index() < tabs.length - 1 ? onTab.next() : tabs.first();
  25.             nextTab.click();
  26.       }, 5000);
  27.  
  28. }
  29. initiateSlideInterval();
  30.  
  31. tabContainer.mouseover(function() {
  32.       clearInterval(slideInterval)
  33. });
  34. tabContainer.mouseout(function() {
  35.       initiateSlideInterval();
  36. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement