I only need to have different marginLeft values of the animate() inside the else if blocks and everything other in the else if blocks should be the same. The script is as follows :
var timeoutID = window.setTimeout(
function(){
if (imgs.index(imgElement) == 0) {
imgElement.animate({
width: "315px",
height: "225px",
marginTop: "-50px",
marginLeft: "-150px",
}, 1500 );
imgElement.css("z-index","100");
imgElement.css("position","absolute");
imgElement.css("opacity","1");
}
else if (imgs.index(imgElement) == 1) {
//The same thing but marginLeft: "-200px"
}
}, 1500);
Just pull your object out into a var: