I writing a plugin that does some toggling and I need a way to check what easing methods are available. I want to support the jQuery UI easing methods when available. It looks like those are in the effects package in the custom builder but, since that could be unchecked, it doesn't seem sufficient to check that jQuery UI is available. I want to check specifically that the easing methods are available.
Asked
Active
Viewed 1,271 times
2 Answers
7
you can check it this way:
if ( $.easing && $.easing.easeInOutQuad ) {
// Use easing function easeInOutQuad
} else {
// Use some other stuff
}
See from line 597
in UI core (http://jqueryui.com/ui/jquery.effects.core.js) .
Link it broken but it should still work.

Andreas Louv
- 46,145
- 13
- 104
- 123
-
Nice find—this got me thinking in the right direction. See my response below for what I ended up using. – ryanve Dec 24 '11 at 18:11
1
Here's what I think I'm going to use:
function verifyEasing(input) {
return 'linear' === input || ($.easing && $.easing.hasOwnProperty(input)) ? input : false;
}
If the input is 'linear'
or if it's available from jQuery UI then it will return it. Otherwise it will return false
. I did it like that b/c if you pass false
as the .toggle()
easing value then it will default to 'swing'
—hence no need to check for swing
specifically. Like this:
$('.target').toggle( 800, verifyEasing(input) );
I guess if you want to check for custom easing functions too then you could add an $.isFunction
check to the boolean:
'linear' === input || ($.easing && $.easing.hasOwnProperty(input)) || $.isFunction(input)

ryanve
- 50,076
- 30
- 102
- 137
-
Instead of returning false i would return `null` - late comment :) – Andreas Louv Nov 20 '12 at 08:49