开发者

Change jQuery effect with plugin options

Im trying to write a small jQuery plugin and be able to change the effects (fadeIn, slideDown etc etc) with options but am having no luck working out how to, for example if I was to add this

fx : fadeIn

then it would change this:

$('.foo').opts.fx('slow');
开发者_StackOverflow中文版

This issue I seem to have is that it doesen't like the placement of the option so am I suppost to wrap it somehow?


I'm no jQuery guru, but since there are no responses, I'll give it a try.

This seems to work for me:

if ($.isFunction($('#foo')[opts.fx])) { // check if it's a valid function
    $('#foo')[opts.fx]("slow");
} else { 
    // ... use default effect ...
}

See demo.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜