0

as an example i take jQuery animate function: normal it works like this:

$("#div1").animate({
                width: '300px',
            }, 1000, function() {
                console.log("animate 1 done");
            });

I would like to have it like this:

animateConfig = [{
                width: '300px',

            }, 1000, function() {
                console.log("animate1 done");
            }];

startAnimate($("#div1"), animateConfig);

function startAnimate(obj, animateConfig) {
    console.log(animateConfig);
    obj.animate(animateConfig);

}

also a fiddle: http://fiddle.jshell.net/hVXKM/1/

2 Answers 2

3

Try:

obj.animate.apply(obj, animateConfig);
Sign up to request clarification or add additional context in comments.

Comments

1

The .animate() method lets you pass an object as a second parameter. That way you can do this:

Docs: .animate( properties, options )

animateConfig = {
    props: { width: '300px' },
    options: {
        duration: 1000,
        complete: function() {
           console.log("animate1 done");
        }
    }
}

So then you can just do this:

function startAnimate(obj, config) {
    obj.animate(config.props, config.options);
}

startAnimate(obj, animateConfig);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.