2012年12月22日土曜日

jQuery purupuru.js の作り方

こんばんは みたび Fuya です。
きょうはjQueryでプラグインを作ったので紹介したいと思います.
あなたは、jQueryでぷるぷるさせたい事ありますか?
とくに冬至は入力フォームをプルプルさせたい衝動に駆られますよね。
jQueryのプラグインは,2種類あります.
  • $('selector').hoge()
  • $.hoge()
今回は,特定のオブジェクトをプルプルさせたいので,前者の呼び出し方法のやつにします.

さっそく作ってみよう

(function($){
$.fn.purupuru=function(){
        return this;
    };
})(jQuery);
これで何もしないjQueryプラグイン $(selector).purupuru(); の完成です.
次にプルプルさせます.

....
    $.fn.purupuru=function(){

        this.css('position','relative');

        for (var i = 0; i< 5; i++) {
            this.animate(
            {
                left: "6px"
            },
            20
            ).animate(
            {
                left: "-6px"
            },
            20
            );
        }
        this.animate(
        {
            left: "0px"
        },
        10,
        function() {
            this.css('position', '');
            this.css('position', '');
        }
        );
....
よいプルプルらいふを!

4 件のコメント:

  1. I found your blog while I was webs writing to find the above information. Your writing has helped me a lot. I'll write a nice post by quoting your post.

    한국야동

    返信削除

  2. I am a fan of reading to add insight to information. Thank you for this great blog. this is here, the few months I am visiting and following you. What I really like about you is that your writing style.

    일본야동


    返信削除
  3. I found your blog while I was webs writing to find the above information. Your writing has helped me a lot. I'll write a nice post by quoting your post.


    일본야동

    返信削除
  4. I have taken your writing very well. Where can I get this information? I want to write good writing like you. Would you like to be a guest blogger on my website?

    한국야동

    返信削除