views:

40

answers:

1

Hi, I need to modify this plugin to rotate images without waiting for animation to end. If you visit that link you might notice that animation restarts at the the end of previous animation but i want images back to back so i dont want to wait for end of the first animation to start next one. Any idea how to do that. Relevant code snippet from that plugin is

el.animate({ left:"-" + el.width() + "px" }, time, "linear", function() {

//reset container position
$(this).css({ left:$("div#imageScroller").width(), right:"" });

//restart animation. Problem is to restart it when last image completey appears with out pausing current animation.
animator($(this), duration, "rtl");

//hide controls if visible
($("div#controls").length > 0) ? $("div#controls").slideUp("slow").remove() : null ;

}); 
+3  A: 

You'd have to approach this completely differently. You'd either have to duplicate all the images and use two containers and as one is completely hidden, move it to the right or pop images off the left side and add them to the right side as they disappear off the page.

methodin
let me try adding image to right side
Ayaz Alavi
Doing the second method requires quite a bit of change to the code as you'd have to set the left property on the images independently and not on the container.
methodin
I suggest the second method. The animator function will almost support it as is. I think you just would need to compare the position of the image with the "viewer" div to see if it's out of view. If it is, stop animation and start again at the beginning.
fehays
2 containers approach is not feasible and I couldn't get how to implement second method. Any ideas how to pop image from left and push it on the right?
Ayaz Alavi
Imagine you have an array of 5 image elements that represent the icons shown. Their starting left styles of 0px, 50px, 100px, 150px, 200px. Your loop will set the left style of each of the image elements -= 10 on each iteration. Then you just check if array[0].left is less than -50 (if your images are 50px wide) and if so, remove it from the array, add it on to the end of the array, and set the left style to 200px and so on.
methodin
great idea, I never thought of using arrays.
Ayaz Alavi