2

i have got a little slideshow. It works fine with the previous and next button. But now I would like to make a slideshow with a play&pause button. Maybe you got a idea?

the javascript:

 function loadSlide(index){
    $('#gallery li').fadeTo(6000, 1.0);
        $('#gallery li').hide()
    .       eq(index).show();
        }

        $('#gallery').data('index',0).find('li').hide();
            loadSlide(0);

        $('#next').on('click',function(e){
          var index = $('#gallery').data('index'),
           numSlides = $('#gallery li').length;

          index = (index + 1) % numSlides;    
            loadSlide(index);
          $('#gallery').data('index',index);
            e.preventDefault();            
    });
        $('#previous').on('click',function(e){
         var index = $('#gallery').data('index'),
            numSlides = $('#gallery li').length;

            index = (index + numSlides - 1) % numSlides;
                loadSlide(index);
        $('#gallery').data('index',index);
            e.preventDefault();
    });
    $("#gallery li img").css({
                    'height':$("#gallery").height()+'px'
                });
                $("#gallery li").each(function(){
                    $(this).css({
                        'margin-left':'+'+parseInt($(this).children("img").width()/2)+'px'
                });
            });

            $("#gallery li img").css({
                    'height':$("#gallery").height()+'px'
                });
                $("#gallery li").each(function(){
                    $(this).css({
                        'margin-left':'+'+parseInt($(this).children("img").width()/2)+'px'
                });
            });
        }

thanks in advance!

D.Steinel
  • 333
  • 5
  • 17

1 Answers1

0

Didn't test, but something like this should work:

$('#start').click( function(){
 t = setInterval( function(){ $('#next').trigger('click'), 2000 } );
});

$('#stop').click( function(){
 clearInterval(t);
});
Ivan Lazarevic
  • 371
  • 2
  • 7
  • **Thanks a lot** for your help! it works fine. I have now a little delay (4000 ms) in it. It looks like this: `$('#play').click( function(){ t = setInterval( function(){ $('#next').trigger('click'), 2000 }, 4000 ); }); $('#pause').click( function(){ clearInterval(t); });` – D.Steinel Mar 22 '12 at 13:10