JQuery Plugin 2 - Passing Options into Your Plugin
jQuery your plugin INTO Options
2023-09-11 14:16:57 时间
overriding the default options with user-supplied options and the jQuery extend() method
eg:
$.fn.pulse = function (options) { // Merge passed options with defaults var opts = $.extend({}, $.fn.pulse.defaults, options); return this.each(function () { // Pulse for (var i = 0; i < opts.pulses; i++) { $(this).fadeTo(opts.speed, opts.fadeLow).fadeTo(opts.speed, opts.fadeHigh); } // Reset to normal $(this).fadeTo(opts.speed, 1); }); }; // Pulse plugin default options $.fn.pulse.defaults = { speed: "slow", pulses: 2, fadeLow: 0.2, fadeHigh: 1 };
call the plugin
// Override only one option $('#myText1').pulse({ pulses: 6 }); // Override all options $('#myText2').pulse({ speed: "fast", pulses: 10, fadeLow: 0.3, fadeHigh: 0.8 });
相关文章
- jquery $.proxy使用 Jquery实现ready()的源码
- jquery中 $ 和 jQuery 及 $() 的区别
- JQuery和Js中,如何让ajax执行完后再继续往下执行?(已解决,示例)
- Jquery和 LigerUI 用PostGetAjax调用数据前台实例!
- webpack 运行时报 jQuery的错
- 使用jquery加载部分视图02-使用$.ajax()
- -第3章 jQuery方法实现下拉菜单显示和隐藏
- 《jQuery Mobile入门经典》—— 1.3 开发者的宝库
- 《jQuery、jQuery UI及jQuery Mobile技巧与示例》——3.4 技巧:更改property和attribute
- jquery easyui动态校验,easyui动态验证
- JQuery中Class选择器怎么用(htmlclass选择器)
- jQuery 操作Cookie 存储 读取 删除等
- 使用requireJS的shim參数,完毕jquery插件的载入
- Jquery学习—jquery的事件
- Ajax与Jquery题库
- jQuery效果-隐藏与显示
- layui jquery ajax,url,type,async,dataType,data