开发者

Callback on each rotation jquery plugin

I'm writing a plugin for an accordion, that auto rotates. I am trying to add a callback that will fire each time a new slide is presented and if the user has set it in the options on init. So, for example:

Callback set in the options:

var defaults = 
    {
    cal开发者_如何学运维lback: function(arg) {}     
    };
var options = $.extend(defaults, options);

Rotation script:

function autorotation() {
   var arg = 'hi'; 
   options.callback.call(this);
}

Init plugin script:

$('element').myplugin({ 
    callback: function(arg) {
        alert(arg);
    }
});

My question is, how do I write this correctly so that I can successfully pass the argument each time the slides rotate to the client outside of the plugin? I hope this make sense to everyone. I tried to be as simple as possible.


Just add the "arg" variable and any other variables you want as parameters of the "call" method call.

var arg = "hello";
var anotherarg = "world";
options.callback.call(this, arg, anotherarg);

And in the callback they'll be available as arguments.

$('element').myplugin({ 
    callback: function(thefirstarg, thesecondarg) {
        alert(thefirstarg);//alerts "hello"
        alert(thesecondarg);//alerts "world"
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜