pageplugin.js
(function($) {$. Pageplugin = function(obj, opt) {var options = $.extend({}, $. Pageplugin.defaults), docoffset, _ua = Navigator.userAgent.toLowerCase(), Is_msie =/msie/.test(_ua), IE6mode =/msie [1-6]\./.test(_ua); if(typeof(OBJ)!==' object ') {obj = $(OBJ) [0];} If(typeof(OPT)!==' object ') {opt = {};} function setoptions(OPT) {if(typeof(OPT)!==' object ') opt = {}; options = $.extend(Options, opt);} The custom method needs to be declared in the following API function SetImage(SRC, callback) {if(typeof(callback) = =' function ') {Callback.call(Api; }}setoptions(Opt; var $orig = $(Obj;//Call internal method Scoremanager.getbo(); Scoremanager.getco();//scoremanager, equivalent to a custom class var Scoremanager =(function() {function Getscore1() {Alert("Key1"); } function Getscore2() {Alert("Key2")1, Getco:getscore2};} () ;//definition Apivar API = {setimage:setimage, Focus:scoremanager.getbo, getbounds:function () {return [ 1, 2];}} ( ' Pageplugin ', API) Span class= "hljs-comment" >;return api;} Set the default property $. Pageplugin.defaults = {margint: 0,MARGINL: 0};} jquery))
How does the
work?
index.js
var api = null;//这里"#page_plugins"我定义为传入控件的内容,可能为id,亦可能class。api = $.PagePlugin("#page_plugins", {marginT: 10,marginL: 20});api.getBounds();api.setImage("h1", function () {});
A nice jquery plug-in template