From 93fdbeb963a9c350f807818c7cc99982942a92f3 Mon Sep 17 00:00:00 2001 From: James Padolsey Date: Mon, 7 Dec 2009 00:37:34 +0800 Subject: [PATCH] Added support for per-property easing --- src/fx.js | 9 ++++++++- test/unit/fx.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/fx.js b/src/fx.js index 529fd4cde9..6bcaac030d 100644 --- a/src/fx.js +++ b/src/fx.js @@ -128,6 +128,11 @@ jQuery.fn.extend({ // Make sure that nothing sneaks out opt.overflow = this.style.overflow; } + if ( jQuery.isArray( prop[p] ) ) { + // Create (if needed) and add to specialEasing + (opt.specialEasing = opt.specialEasing || {})[p] = prop[p][1]; + prop[p] = prop[p][0]; + } } if ( opt.overflow != null ) { @@ -387,7 +392,9 @@ jQuery.fx.prototype = { this.state = n / this.options.duration; // Perform the easing function, defaults to swing - this.pos = jQuery.easing[this.options.easing || (jQuery.easing.swing ? "swing" : "linear")](this.state, n, 0, 1, this.options.duration); + var specialEasing = this.options.specialEasing && this.options.specialEasing[this.prop]; + var defaultEasing = this.options.easing || (jQuery.easing.swing ? "swing" : "linear"); + this.pos = jQuery.easing[specialEasing || defaultEasing](this.state, n, 0, 1, this.options.duration); this.now = this.start + ((this.end - this.start) * this.pos); // Perform the next step of the animation diff --git a/test/unit/fx.js b/test/unit/fx.js index 9b2f9d8b12..b959799386 100644 --- a/test/unit/fx.js +++ b/test/unit/fx.js @@ -586,3 +586,37 @@ test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () start(); }); }); + +test("animate with per-property easing", function(){ + + expect(3); + stop(); + + var _test1_called = false; + var _test2_called = false; + var _default_test_called = false; + + jQuery.easing['_test1'] = function() { + _test1_called = true; + }; + + jQuery.easing['_test2'] = function() { + _test2_called = true; + }; + + jQuery.easing['_default_test'] = function() { + _default_test_called = true; + }; + + jQuery({a:0,b:0,c:0}).animate({ + a: [100, '_test1'], + b: [100, '_test2'], + c: 100 + }, 400, '_default_test', function(){ + start(); + ok(_test1_called, "Easing function (1) called"); + ok(_test2_called, "Easing function (2) called"); + ok(_default_test_called, "Easing function (_default) called"); + }); + +}); \ No newline at end of file