Question

http://jsfiddle.net/UWLsB/189/

I am trying to make the image slide to the left after 7 seconds, how come it's not working?

Html:

<div id="container">
    <div id="pack">
        <img id="pack" src="http://imgur.com/uGMzOGM.png">
    </div>

Javascript:

function FetchData() {
    $("#pack").css('margin-left', 0);
    $("#pack").css('margin-right', 0);
    $("#pack").animate({
        left: '-1000px'
    }, 'slow');
});
}
setTimeout(FetchData, 7000);

CSS:

#pack {
    margin: 5px auto;
    position:fixed;
}
#container {
    overflow:hidden;
}
Was it helpful?

Solution

You just have a syntax error. The }); line should be removed entirely:

http://jsfiddle.net/UWLsB/190/

I think you meant to use syntax that would have } and ) on the same line or got it from some tutorial like:

setTimeout(function () {
    // .animate call stuff here
}, 7000);

By the way, you could do this purely with CSS using animations:

http://jsfiddle.net/UWLsB/192/

OTHER TIPS

http://jsfiddle.net/UWLsB/191/

function FetchData() {
    $("#pack").css('margin-left', 0);
    $("#pack").css('margin-right', 0);
    $("#pack").animate({
        left: '-1000px'
    }, 'slow');
}
setTimeout(FetchData, 7000);

you can also make the first two lines of the function into one like this

$("#pack").css({"margin-left": "0", "margin-right": "0"});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top