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.
精彩评论