Skip to content

Commit 93fdbeb

Browse files
padolseyjeresig
authored andcommitted
Added support for per-property easing
1 parent 62a3445 commit 93fdbeb

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/fx.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ jQuery.fn.extend({
128128
// Make sure that nothing sneaks out
129129
opt.overflow = this.style.overflow;
130130
}
131+
if ( jQuery.isArray( prop[p] ) ) {
132+
// Create (if needed) and add to specialEasing
133+
(opt.specialEasing = opt.specialEasing || {})[p] = prop[p][1];
134+
prop[p] = prop[p][0];
135+
}
131136
}
132137

133138
if ( opt.overflow != null ) {
@@ -387,7 +392,9 @@ jQuery.fx.prototype = {
387392
this.state = n / this.options.duration;
388393

389394
// Perform the easing function, defaults to swing
390-
this.pos = jQuery.easing[this.options.easing || (jQuery.easing.swing ? "swing" : "linear")](this.state, n, 0, 1, this.options.duration);
395+
var specialEasing = this.options.specialEasing && this.options.specialEasing[this.prop];
396+
var defaultEasing = this.options.easing || (jQuery.easing.swing ? "swing" : "linear");
397+
this.pos = jQuery.easing[specialEasing || defaultEasing](this.state, n, 0, 1, this.options.duration);
391398
this.now = this.start + ((this.end - this.start) * this.pos);
392399

393400
// Perform the next step of the animation

test/unit/fx.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,3 +586,37 @@ test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function ()
586586
start();
587587
});
588588
});
589+
590+
test("animate with per-property easing", function(){
591+
592+
expect(3);
593+
stop();
594+
595+
var _test1_called = false;
596+
var _test2_called = false;
597+
var _default_test_called = false;
598+
599+
jQuery.easing['_test1'] = function() {
600+
_test1_called = true;
601+
};
602+
603+
jQuery.easing['_test2'] = function() {
604+
_test2_called = true;
605+
};
606+
607+
jQuery.easing['_default_test'] = function() {
608+
_default_test_called = true;
609+
};
610+
611+
jQuery({a:0,b:0,c:0}).animate({
612+
a: [100, '_test1'],
613+
b: [100, '_test2'],
614+
c: 100
615+
}, 400, '_default_test', function(){
616+
start();
617+
ok(_test1_called, "Easing function (1) called");
618+
ok(_test2_called, "Easing function (2) called");
619+
ok(_default_test_called, "Easing function (_default) called");
620+
});
621+
622+
});

0 commit comments

Comments
 (0)