开发者

Basics behind extending jQuery with fn.extend - accessing members

开发者 https://www.devze.com 2023-03-13 09:11 出处:网络
I made this simple extension of jQuery: (function($) { $.fn.extend({ animateleft: function(amount) { $().an开发者_开发百科imate({

I made this simple extension of jQuery:

 (function($)
    {      
        $.fn.extend({          

            animateleft: function(amount) {              
                    $().an开发者_开发百科imate({
                            left: amount
                            }, 300, function() { }); 

                    return $();    
               }      
         });  
    })(jQuery);

I understand that by returning $() it enables chaining. I dont know what exactly is contained in $() however. The animate function doesnt seem to get triggered when I try something like:

$('#container').animateleft("+=300"); 

Which I think should work if $('#container') is whats passed in to the extensions as $().


Inside a plugin method, the selected elements are referenced by this. So it should be:

(function($) {      
    $.fn.extend({          
        animateleft: function(amount) {              
            this.animate({
                left: amount
            }, 300, function() { }); 
            return this;    
        }      
    });  
})(jQuery);

$() just calls the jQuery function with no parameter, which returns a new (empty) jQuery object.

0

精彩评论

暂无评论...
验证码 换一张
取 消