首页 > Web开发 > 详细

jQuery插件开发前准备(三)

时间:2016-08-17 23:08:18      阅读:209      评论:0      收藏:0      [点我收藏+]

【MyPlugin核心函数实现】

  从上两节中我们已经知道了MyPlugin是个构造函数,需要这$.fn.MyPlugin()中实例化,所以MyPlugin应该定义如下:

var MyPlugin = (function() {
    function MyPlugin(element, options) {
        // 将用户配置项与默认选项进行深拷贝
        this.settings = $.extend(true, $.fn.MyPlugin.defaultValue, options || {});
        this.element = element;
        this.init();
    }
    MyPlugin.prototype = {
        init: function() {

        }
        //more
    };
    // 必须要将该对象返回出去
return MyPlugin; })();

  因为我们写的插件,很多时候需要有默认值和用户自定义值,所以就需要提供接口给其他开发调用。

$.fn.MyPlugin.defaultValue = {
    // 圆大小
    size: ‘25‘,
    // 环大小
    border: ‘5‘,
    // 环背景
    bgColor: ‘#CCC‘,
    // 进度背景
    frontColor: ‘#008000‘,
    // 进度条字体大小
    fontSize: ‘12px‘
};
  通过深拷贝的方式,将用户设定值,和默认值整合在一起

  this.settings = $.extend(true, $.fn.MyPlugin.defaultValue, options || {});

jQuery插件开发前准备(三)

原文:http://www.cnblogs.com/songxiaoyu/p/5782121.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!