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

如何創(chuàng)建簡單的 jQuery 插件?

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

問題描述

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

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});
    }); 
}

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

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.

解決辦法是什么?

推薦答案

對于插件創(chuàng)作嘗試這種方式,更可靠:

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>

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

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

相關(guān)文檔推薦

jQuery/JavaScript Library for avatar creation?(用于創(chuàng)建頭像的 jQuery/JavaScript 庫?)
How to do following mask input problem?(如何做以下掩碼輸入問題?)
Issues Setting Value/Label Using DropKick Javascript(使用 DropKick Javascript 設(shè)置值/標(biāo)簽的問題)
how to unit-test private methods in jquery plugins?(如何對 jquery 插件中的私有方法進行單元測試?)
stellar.js - configuring offsets / aligning elements for a vertical scrolling website?(stellar.js - 為垂直滾動網(wǎng)站配置偏移量/對齊元素?)
jQuery masked input plugin. select all content when textbox receives focus(jQuery 屏蔽輸入插件.當(dāng)文本框獲得焦點時選擇所有內(nèi)容)
主站蜘蛛池模板: 国产一区二区在线播放 | 成人亚洲一区 | 精品国产一区二区三区性色av | 久久国产香蕉 | 涩涩鲁亚洲精品一区二区 | 中文字幕91 | 成人网在线观看 | 国产成人综合在线 | 在线播放精品视频 | 在线观看h视频 | 久久不卡 | 中文字幕亚洲视频 | 久久www免费视频 | 亚洲高清视频在线观看 | 亚洲高清视频一区二区 | 在线精品国产 | 欧美国产精品一区二区三区 | 亚洲成人一区二区 | 国产电影精品久久 | 男人的天堂一级片 | 乳色吐息在线观看 | 国产传媒在线观看 | 怡红院怡春院一级毛片 | 91精品国产综合久久久动漫日韩 | 精品国产乱码久久久久久丨区2区 | 亚洲第一黄色网 | 午夜成人在线视频 | 99热在这里只有精品 | 91麻豆产精品久久久久久夏晴子 | 亚洲精品粉嫩美女一区 | 女同久久另类99精品国产 | 中文在线www| 日韩欧美国产一区二区 | 中文字幕一区在线观看视频 | 亚洲人人 | 日韩综合网 | 91精品国产91久久综合桃花 | 亚洲一区二区在线 | 精品网站999www | 狠狠爱免费视频 | 国产欧美在线观看 |