First off, I think I may have some syntax errors, but I don't know where since most of this code is copy paste from JQuery then modified for my needs...
$(document).ready(function() {
var stage = $(".gallery");
var stageoffset = stage.offset();
var stageleft = stageoffset.left + 600;
var lastimage = $("img:last");
var imageoffset = lastimage.offset();
var imageleft = imageoffset.left;
if(imageleft > stageleft) {
alert("Passed to the right.");
}
function gallery () {
$("#image").animate({"margin-left":"+=100px"}, 1000, "linear");
}
setInterval(gallery, 1000);
});
Second, here is a JSFiddle...
I know that the animation code is right, because that works fine. Since it is not running, I assume there is a syntax error. However, I'm pretty new to JQuery, and I can't find it.
The point of this code is to move the images, then when they leave the container to the right, the script will alert a message. Eventually, I will use this trigger to delete the last image, and clone it in front to produce a carousel. But, that's later. Am I implementing this code right?
Thanks in advanced!
-
in a JavaScript variable name. E.g.,stage-offset
is an invalid variable name. I recommend reading some basic JavaScript tutorials. – T.J. Crowder 1 hour ago