Check if jQuery UI easing methods are available

I am writing a plugin that does some switching, and I need a way to check which mitigation methods are available. I want to support jQuery UI easing methods when available. It looks like they are in the effects package in a custom builder , but since this could be turned off, it does not seem enough to verify that the jQuery UI is available. I want to make sure that mitigation methods are available.

+4
source share
2 answers

you can check it as follows:

if ( $.easing && $.easing.easeInOutQuad ) { // Use easing function easeInOutQuad } else { // Use some other stuff } 

See line 597 in the user interface kernel ( http://jqueryui.com/ui/jquery.effects.core.js ).

Tie it broken, but it should still work.

+7
source

Here is what I think I will use:

 function verifyEasing(input) { return 'linear' === input || ($.easing && $.easing.hasOwnProperty(input)) ? input : false; } 

If the input is 'linear' or if it is accessible from the jQuery UI, it will return it. Otherwise, it will return false . I did it like b / c, if you pass false as the attenuation value .toggle() , then the default will be 'swing' - no need to check for swing . Like this:

 $('.target').toggle( 800, verifyEasing(input) ); 

I think if you want to test custom relief functions as well, you can add a $.isFunction to the boolean:

 'linear' === input || ($.easing && $.easing.hasOwnProperty(input)) || $.isFunction(input) 
+1
source

Source: https://habr.com/ru/post/1387783/


All Articles