Advertisement
linux4me

Wordpress JQuery Post Div Slideshow

Jan 2nd, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 3.89 KB | None | 0 0
  1. jQuery(document).ready(function(){
  2.     var play_div_slideshow_tid;
  3.     jQuery('.div_slideshow_container').each(function() {
  4.         jQuery(this).prepend('<div class="play_div_slideshow"><a href="javascript: void(0);" class="play_div_slideshow_link">Play Slideshow</a></div><div class="div_slideshow_nav"><a href="javascript: void(0);"  class="div_slideshow_previous div_slideshow_nav_button" data-direction="-1"><img src="' + imagedir + 'nav_button_prev.png" width="35" height="35" alt="Prev" /></a> <span class="div_slideshow_start"></span> of <span class="div_slideshow_end"></span> <a href="javascript: void(0);" class="div_slideshow_next div_slideshow_nav_button" data-direction="1"><img src="' + imagedir + 'nav_button_next.png" width="35" height="35" alt="Next" /></a></div>');
  5.         jQuery(this).children('.div_slide').each(function(index, Element) {
  6.             if (index != 0) {
  7.                 jQuery(this).hide();
  8.             }
  9.         });
  10.         jQuery(this).find('.div_slideshow_start').text('1');
  11.         jQuery(this).find('.div_slideshow_end').text(jQuery(this).children('div.div_slide').length);
  12.     });
  13.    
  14.     jQuery('.div_slideshow_previous').mouseenter(function() {
  15.         jQuery(this).children('img').attr('src', imagedir + 'nav_button_prev_active.png');
  16.     });
  17.    
  18.     jQuery('.div_slideshow_previous').mouseleave(function() {
  19.         jQuery(this).children('img').attr('src', imagedir + 'nav_button_prev.png');
  20.     });
  21.    
  22.     jQuery('.div_slideshow_next').mouseenter(function() {
  23.         jQuery(this).children('img').attr('src', imagedir + 'nav_button_next_active.png');
  24.     });
  25.    
  26.     jQuery('.div_slideshow_next').mouseleave(function() {
  27.         jQuery(this).children('img').attr('src', imagedir + 'nav_button_next.png');
  28.     });
  29.    
  30.     jQuery('.div_slideshow_nav_button').click(function() {
  31.         var currentslide = parseInt(jQuery(this).parents('div.div_slideshow_container').find('span.div_slideshow_start').text()) -1,
  32.             navdirection = parseInt(jQuery(this).attr('data-direction')), newslide = currentslide + navdirection,
  33.             lastindex = jQuery(this).parents('div.div_slideshow_container').children('div.div_slide').length - 1;
  34.             //alert('currentslide = ' + currentslide + ' and newslide = ' + newslide + ' and lastindex = ' + lastindex);
  35.             //alert('image directory is ' + imagedir);
  36.         if (newslide > lastindex) {
  37.             newslide = 0;
  38.         } else if (newslide < 0) {
  39.             newslide = lastindex;
  40.         }
  41.         jQuery(this).parents('div.div_slideshow_container').find('span.div_slideshow_start').text(newslide + 1);
  42.         jQuery(this).parents('div.div_slideshow_container').children('div.div_slide').eq(currentslide).hide("slide", { direction: "left" }, 500, function() {
  43.             jQuery(this).parents('div.div_slideshow_container').children('div.div_slide').eq(newslide).show("slide", { direction: "right" }, 500);
  44.         });
  45.     });
  46.    
  47.     jQuery('.play_div_slideshow_link').click(function() {
  48.         if (jQuery(this).text() == 'Play Slideshow') {
  49.             jQuery(this).text('Stop Slideshow');
  50.             var theobject = jQuery(this), currentslide, newslide, lastindex;
  51.             play_div_slideshow_tid = setInterval(function(thisobject = theobject) {
  52.                 currentslide = parseInt(thisobject.parents('div.div_slideshow_container').find('span.div_slideshow_start').text()) -1,
  53.                     newslide = currentslide + 1,
  54.                     lastindex = thisobject.parents('div.div_slideshow_container').children('div.div_slide').length - 1;
  55.                 if (newslide > lastindex) {
  56.                     newslide = 0;
  57.                 } else if (newslide < 0) {
  58.                     newslide = lastindex;
  59.                 }
  60.                 thisobject.parents('div.div_slideshow_container').find('span.div_slideshow_start').text(newslide + 1);
  61.                 thisobject.parents('div.div_slideshow_container').children('div.div_slide').eq(currentslide).hide("slide", { direction: "left" }, 500, function() {
  62.                     thisobject.parents('div.div_slideshow_container').children('div.div_slide').eq(newslide).show("slide", { direction: "right" }, 500);
  63.                 });
  64.             }, 3000);
  65.         } else {
  66.             jQuery(this).text('Play Slideshow');
  67.             clearInterval(play_div_slideshow_tid);
  68.         }
  69.     });
  70. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement