当前位置: 代码迷 >> 综合 >> jQuery插件编写模板
  详细解决方案

jQuery插件编写模板

热度:71   发布时间:2023-09-13 20:31:18.0

jQuery插件编写模板

;(function($,window,document,undefined){//定义插件myplugin,在插件中使用MyPlugin对象$.fn.videoPlay = function(options){return this.each(function() { //保持插件的链式调用,确保插件返回this关键字//创建MyPlugin的实体var video = new VideoPlay(this,options);//调用其方法return video.init();})}//定义MyPlugin对象var VideoPlay = function(ele,opt){this.$element = ele,           //获取到的jQuery对象console.log(this);// 设置默认参数this.defaults = {},this.options = $.extend({}, this.defaults, opt);//定义全局变量var _this = this,navIndex = 0;                                 //当前图片的号数//定义私有方法//this.auto = function(){//    if(_.options.auto===false){//        return false;//    }//    clearInterval(timer);//    timer = setInterval(function(){//        _.next();//    },4000);//}}//定义MyPlugin对象的方法VideoPlay.prototype = {init:function(){//调用私有方法//处理DOMconsole.log(0);}}})(jQuery,window,document);
  相关解决方案