SHARE
TWEET

Auto slide for Twenty Eleven Featured Posts Slider

RavanH May 6th, 2012 246 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* * *
  2.  * Auto-slide the Twenty Eleven Featured Posts Slider
  3.  * by RavanH -- http://4visions.nl/?p=1001 --
  4.  * Paste code in a text widget in the Showcase Sidebar.
  5.  * Adapt variables 'slide_speed' and 'slide_delay' to change
  6.  * the slider effect and timeout speed in milliseconds.
  7.  * The variable 'slide_delay_first' is meant for the first
  8.  * timeout during which page elements like images are still
  9.  * loading which usually needs some extra time while
  10.  * slide_effect and slide_easing control more advanced slider
  11.  * behaviour. Read the instructions for available options.
  12.  */
  13. (function($) {
  14.   var slide_delay_first = 6000; /* first timeout in ms */
  15.   var slide_delay = 5000; /* timeouts in ms */
  16.   var slide_speed = 300; /* effect speed in ms */
  17.   var slide_effect = 'slide'; /* available options are 'slide', 'fade' or '' (default) */
  18.   var slide_easing = 'swing'; /* available options are  'linear' or 'swing' (default) */
  19.  
  20.   var slide_timeout;
  21.   $('section.featured-post').slice(1).css('display', 'none');
  22.   slide_setTimeout(slide_delay_first, $('nav.feature-slider a.active').parent().next().children().first() );
  23.  
  24.   $('.feature-slider a').click(function() {
  25.     window.clearTimeout(slide_timeout);
  26.     if (slide_effect == 'fade') {
  27.        $(this.hash).css({ display: 'none', opacity: 1, visibility: 'visible' }).fadeIn(slide_speed, slide_easing, slide_setTimeout(slide_delay, $(this).parent().next().children().first()) );
  28.     } else if (slide_effect == 'slide') {
  29.       $(this.hash).css({ display: 'none', opacity: 1, visibility: 'visible' }).slideDown(slide_speed, slide_easing, slide_setTimeout(slide_delay, $(this).parent().next().children().first()) );
  30.     } else {
  31.       $(this.hash).css({ display: 'none', opacity: 1, visibility: 'visible' }).show(slide_speed, slide_easing, slide_setTimeout(slide_delay, $(this).parent().next().children().first()) );
  32.     }
  33.   });
  34.  
  35.   function slide_setTimeout(delay, next_link) {
  36.     if (next_link.length == 0) {
  37.       next_link = $('nav.feature-slider a').first();
  38.     }
  39.     if (next_link.length !== 0) {
  40.       if (slide_effect == 'fade') {
  41.         slide_timeout = window.setTimeout(function(){$('section.featured-post').filter(':visible').fadeOut(slide_speed, slide_easing, function(){next_link.trigger('click');});}, delay);
  42.       } else if (slide_effect == 'slide') {
  43.         slide_timeout = window.setTimeout(function(){$('section.featured-post').filter(':visible').slideUp(slide_speed, slide_easing, function(){next_link.trigger('click');});}, delay);
  44.       } else {
  45.         slide_timeout = window.setTimeout(function(){$('section.featured-post').filter(':visible').hide(slide_speed, slide_easing, function(){next_link.trigger('click');});}, delay);
  46.       }
  47.     }
  48.   }
  49. })(jQuery);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top