Bug Tracker

Modify

Ticket #7375 (closed enhancement: plugin)

Opened 3 years ago

Last modified 14 months ago

Allow custom easing functions with animate

Reported by: janne.aukia@… Owned by:
Priority: undecided Milestone:
Component: effects Version: 1.4.3
Keywords: needsreview Cc:
Blocking: Blocked by:

Description

I would like to make a jQuery plugin which would allow using cubic easing in the same way as in CSS3 transformations. As far as I know, this is currently not possible, since currently all easings need to be named functions under jquery.easing and they cannot take extra parameters.

What I would like to have would be something like the following:

function constructCubicEasing(p1x,p1y,p2x,p2y) {
    return function( p, n, firstNum, diff ) {
        // here setup the actual easing func based on p1x...p2y
    };
}

$(".block").animate({"left": "0px"}, constructCubicEasing(0.42,0.0,0.58,1.0));

So instead of passing named arguments for easing functions (such as "swing" or "linear") one could pass an actual function.

Another alternative would be to have a way to pass parameters to the easing function, something like:

jquery.easing.cubic = function(p, n, firstNum, diff, extraParams) {
    // here setup the actual easing func based on p1x...p2y in extraParams
}

$(".block").animate({"left": "0px"}, "cubic", null, {p1x:0.42,p1y:0.0,p2x:0.58,p2y:1.0});

The motivation behind these is that designers often want to tweak easing parameters to please their tastes, and for them, having some config params would be nice.

Change History

comment:1 Changed 3 years ago by rwaldron

  • Keywords needsreview added
  • Status changed from new to open
  • Component changed from unfiled to effects
  • Milestone 1.5 deleted

comment:2 Changed 2 years ago by gnarf

One thing to note... The "standard" fx calls to easing functions ALWAYS use firstNum = 0, diff = 1 - p is the actual "percent" and n is a number of milliseconds...

comment:3 follow-up: ↓ 4 Changed 2 years ago by john

  • Status changed from open to closed
  • Resolution set to plugin

I would be inclined to do something like this:

(function(){
  var num = 1;

  this.constructCubicEasing = function(p1x,p1y,p2x,p2y) {
    var name = "cubic" + num;

    jQuery.easing[ name ] = function( p, n, firstNum, diff ) {
        // here setup the actual easing func based on p1x...p2y
    };

    num++;

    return name;
  };
})();

Then you could just do:

$(".block").animate({"left": "0px"}, constructCubicEasing(0.42,0.0,0.58,1.0));

comment:4 in reply to: ↑ 3 Changed 21 months ago by mail@…

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.