0

This is my first post on here but I have used this site as a great reference for years. I am simply trying to get my slide show to pause when I hover over it. The code is below. I tried using the jquery hover to stop it but I am not having any success. Anyone have any ideas?

$(function() {
    // create the image rotator
    setInterval("rotateImages()", 7000);
});

function rotateImages() {
   var oCurPhoto = $('#photoShow div.current');
   var oNxtPhoto = oCurPhoto.next();
   if (oNxtPhoto.length == 0)
      oNxtPhoto = $('#photoShow div:first');

    oCurPhoto.removeClass('current').addClass('previous');
    oNxtPhoto.css({ opacity: 0.0 }).addClass('current').animate({ opacity: 1.0 }, 1000,
        function() {
            oCurPhoto.removeClass('previous');
        });
}
Nicos Karalis
  • 3,724
  • 4
  • 33
  • 62

2 Answers2

0

In the way you are implementing i can only recomend a var to store the status of the rotation.

like this:

var canRotate = true;

$(function() {
    // create the image rotator
    setInterval("rotateImages()", 7000);
});

function rotateImages() {
   if(!canRotate) { return; }
   var oCurPhoto = $('#photoShow div.current');
   var oNxtPhoto = oCurPhoto.next();
   if (oNxtPhoto.length == 0)
      oNxtPhoto = $('#photoShow div:first');

    oCurPhoto.removeClass('current').addClass('previous');
    oNxtPhoto.css({ opacity: 0.0 }).addClass('current').animate({ opacity: 1.0 }, 1000,
        function() {
            oCurPhoto.removeClass('previous');
        });
}

This should work fine.

P.S.: You could also look for the method .stop() in jQuery library. this will send a stop request to the object that is curently animating.

Nicos Karalis
  • 3,724
  • 4
  • 33
  • 62
0

It maybe ugly but this should work

$(function() {
    var myTimer = 0;
    myTimer = setInterval("rotateImages()", 7000);

    $('#photoShow').mouseover(function() {
            clearInterval(myTimer);
      }).mouseout(function(){
            myTimer = setInterval("rotateImages()", 7000);
      });
});
Lance
  • 3,193
  • 2
  • 32
  • 49