Search code examples
javascripthtmlcsstestingpack

Javascript after 7 seconds slide image


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;
}

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/