/ Published in: JavaScript
A simple jQuery Plugin I made to remind myself how to create a jQuery Plugin following the tips from http://docs.jquery.com/Plugins/Authoring
Demo - http://jsfiddle.net/hya58/1/
Expand |
Embed | Plain Text
(function($) { $.fn.megaEdit = function(options) { var settings = { name: "This is a default name", option1: "This is Option 1's value" }; var helpers = { log: function(message) { if (typeof console != "undefined") { console.log(message); } }, rand: function() { return Math.round(Math.random() * 20); } }; var eventHandlers = { onLoaded: function() { helpers.log(settings.name + " loaded!"); } }; if (options !== undefined) { $.extend(settings, options); } return this.each(function() { $this = $(this); $this.bind("megaEdit.loaded", eventHandlers.onLoaded); $this.val("Random Number: " + helpers.rand() + "\nMy name is: " + settings.name + "\nOption2: " + settings.option1); $this.trigger("megaEdit.loaded"); }); } })(jQuery);
Comments
Subscribe to comments
You need to login to post a comment.

/** * @classDescription 模拟Marquee,无间断滚动内容 * @author Aken Li(www.kxbd.com) * @DOM *
*
* * *
** @CSS * #marquee {width:200px;height:50px;overflow:hidden;} * @Usage * $('#marquee').kxbdMarquee(options); * @options * isEqual:true,//所有滚动的元素长宽是否相等,true,false * loop: 0,//循环滚动次数,0时无限 * direction: 'left',//滚动方向,'left','right','up','down' * scrollAmount:1,//步长 * scrollDelay:20//时长 */ (function($){