Javascript – dynamically change jquery innerfade

dynamicjavascriptjquery-plugins

I have a small form of transition settings next to some images I'm rotating using a jquery innerfade plugin. What I would like is when the user selects a new transition setting (ie, timeout) the innerfade dynamically updates the timeout setting so the user can preview what this change will look like. But I'm not sure the best way to do this? is it possible without altering the script?

$('#foo').innerfade({
    timeout: $('#bar').val()
});

my current approach doesn't work. I've also tried unbinding the innerfade from #foo, but that didn't work either and the script doesn't have a remove function.

How can I make this work?

Best Answer

You could replace the $.innerfade.next, which actually sets the timer, without modifying the plugin.

For example: (Untested)

$.innerfade.next = function(elements, settings) {
    if (!$.data(settings.container, 'paused')) {
        $.innerfade.animate(elements, settings);
    }

    if (settings.timeoutElem)
        settings.timeout = settings.timeoutElem.val();

    setTimeout((function() {
        $.innerfade.next(elements, settings);
    }), settings.timeout);
};


$('#foo').innerfade({
    timeout: $('#bar').val()
    timeoutElem: $('#bar')
});

You'd have to re-test this every time the plugin is updated.