久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何創建簡單的 jQuery 插件?

How to create simple jQuery plugin?(如何創建簡單的 jQuery 插件?)
本文介紹了如何創建簡單的 jQuery 插件?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

這個測試插件應該是這樣工作的:當一個元素被點擊時,它會向下移動.就那么簡單.

This test plugin, is supposed to work like this: When an element is clicked, it moves down. Simple as that.

jQuery.fn.moveDown = function(howMuch){
    $(this).css("border", "1px solid black");
    $(this).click(function(){

        $(this).css("position", "relative");
        $(this).animate({top: '+='+howMuch});
    }); 
}

問題是,當一個元素被點擊時,它不僅會移動被點擊的元素,還會移動應用插件的所有其他元素.

The problem is, when an element is clicked, it not only moves the clicked element but also ALL the other elements which the plugin was applied to.

解決辦法是什么?

推薦答案

對于插件創作嘗試這種方式,更可靠:

For plugin authoring try this way, much more solid:

這是 jsFiddle 示例.

插件:

(function($){
    $.fn.extend({
        YourPluginName: function(options) {
                var defaults = {
                      howMuch:'600',
                      animation: '',//users can set/change these values
                      speed: 444,
                      etc: ''
                }
        };

       options = $.extend(defaults, options);

       return this.each(function() {
          var $this = $(this);              
          var button = $('a', $this);// this represents all the 'a' selectors;
                                            // inside user's plugin definition.

          button.click(function() {
            $this.animate({'top':options.howMuch});//calls options howMuch value
          });
       });
})(jQuery);

用戶文件:

$(function() {
   $('#plugin').YourPluginName({
     howMuch:'1000' //you can give chance users to set their options for plugins
   });
});

<div id="plugin">
  <a>1</a>
  <a>2</a>
  <a>3</a>
</div>

這篇關于如何創建簡單的 jQuery 插件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

jQuery/JavaScript Library for avatar creation?(用于創建頭像的 jQuery/JavaScript 庫?)
How to do following mask input problem?(如何做以下掩碼輸入問題?)
Issues Setting Value/Label Using DropKick Javascript(使用 DropKick Javascript 設置值/標簽的問題)
how to unit-test private methods in jquery plugins?(如何對 jquery 插件中的私有方法進行單元測試?)
stellar.js - configuring offsets / aligning elements for a vertical scrolling website?(stellar.js - 為垂直滾動網站配置偏移量/對齊元素?)
jQuery masked input plugin. select all content when textbox receives focus(jQuery 屏蔽輸入插件.當文本框獲得焦點時選擇所有內容)
主站蜘蛛池模板: 久久性色| 一级特黄色片 | 97视频免费在线观看 | 首尔之春在线看 | 亚洲欧美国产高清va在线播放 | 久草资源在线观看 | 一区二区精品在线 | 黄色录像免费看 | 视频一区二区在线播放 | 国产成人精品一区二区三区福利 | 在线成人| 亚洲av毛片成人精品 | www.久 | 在线伊人网 | 中文字幕国产精品 | 成人毛片在线播放 | 成人a级片 | www.婷婷.com| 国产欧美综合一区二区三区 | 色网站女女 | 黄色免费网站在线观看 | 97在线免费观看 | 国产精品一区二区三区四区五区 | 亚洲欧美视频在线观看 | 日本国产在线观看 | 国产精品成人免费精品自在线观看 | 日本在线观看一区 | 福利片国产 | 一区二区水蜜桃 | 超碰在线小说 | 天天躁日日躁狠狠很躁 | 98国产精品| 在线观看一区 | 欧美xx孕妇 | 91丨九色丨国产在线 | 国产白丝精品91爽爽久久 | 成年人一级片 | 韩国理论在线 | 国产成人在线免费观看 | 一区视频在线 | 亚洲视频一区二区三区四区 |