zoukankan      html  css  js  c++  java
  • 一个不错的jquery插件模版

     

    • 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);
      }
      
      //自定义方法,需要在下面api声明
      function setImage(src, callback) {
      
          if (typeof (callback) == 'function') {
              callback.call(api);
          }
      }
      
      setOptions(opt);
      var $orig = $(obj);
      
      //调用内部方法
      ScoreManager.getBo();
      ScoreManager.getCo();
      
      //scoreManager,相当于自定义类
      var ScoreManager = (function () {
          function getScore1(){
              alert("key1");
          }
      
          function getScore2(){
              alert("key2");
          }
      
          return {
              getBo: getScore1,
              getCo: getScore2
          };
      
      }());
      
       //定义api
      var api = {
          setImage: setImage,
          focus:ScoreManager.getBo,
          getBounds: function () {
              return [1, 2];
          }
      
      };
      
      $orig.data('PagePlugin', api);
      return api;
      }
      
      //设置默认属性
      $.PagePlugin.defaults = {
      	marginT: 0,
      	marginL: 0
      };
      }(jQuery));
    • 如何使用?
      index.js

      var api = null;
      
      //这里"#page_plugins"我定义为传入控件的内容,可能为id,亦可能class。
      
      api = $.PagePlugin("#page_plugins", {
      marginT: 10,
      marginL: 20
      });
      
      api.getBounds();
      api.setImage("h1", function () {
      
      });
  • 相关阅读:
    如何让在JAVA中定义常量池
    java常量池概念
    Efficient Counter in Java
    看到关于JS线程的两篇文章
    Java Collection
    java学习书籍介绍--csdn上一位前辈介绍
    myeclipse快捷键
    数组
    错误处理和时间函数
    函数01
  • 原文地址:https://www.cnblogs.com/liuwenbohhh/p/4342944.html
Copyright © 2011-2022 走看看