|
-
March 15th, 2011, 12:59 AM
#1
Help, setTimeout not working properly.
Hey,
I have been trying to create an infinite loop using "setTimeout" in javascript to animate a slideshow.
Following is the code I am using :
Code:
$(document).ready(function()
{
var currentPosition = 1;
var slideWidth = 640;
var slides = $('.slide');
var numberOfSlides = slides.length;
// Wrap all .slides with #slideInner div
slides.wrapAll('<div id="slideInner"></div>')
// Set #slideInner width equal to total width of all slides
$('#slideInner').css('width', slideWidth * numberOfSlides);
slidetheslider(currentPosition,numberOfSlides);
});
function slidetheslider(pos,numSlide)
{
var curPos = pos ;
var numberSlide = numSlide ;
$('#slideInner').animate({
'marginLeft' : 640*(-curPos)
},1500 );
if (curPos >= numberSlide-1)
{
curPos = 0;
}
else
{
curPos = curPos + 1;
}
window.setTimeout("slidetheslider(curPos,numberSlide)",3000);
};
The setTimeout works as it is supposed to if I do something like ( window.setTimeout("slidetheslider(6,6)",3000); ) but doesn't in the above code.
It is already 48hours of headache and I couldn't find a clue.Any help ?
Thanks a lot
Lisa
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|