创建 jQuery 插件的链接:
http://learn.jquery.com/plugins/basic-plugin-creation/
这个怎么样:
;(function ($) {
$.fn.myPlugin = function (options) {
// define defaults
var defaults = {
left1: 20,
left2: 0,
duration: 1000
};
var o = $.extend(defaults, options);
this.each(function() {
var $this = $(this);
$({left: o.left1}).animate({left: o.left2}, {
duration: o.duration,
easing:'linear',
step: function() {
$this.text(this.left);
},
complete: function() {
$this.text(this.left);
}
});
});
return this;
}
})(jQuery);
// end
用法是这样的:
$('#pp').myPlugin({
left1: 20,
left2: 0,
duration: 1000
});