2011-12-23 27 views

回答

7

您可以檢查它這樣說:

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

從線597見UI核心( http://jqueryui.com/ui/jquery.effects.core.js)。

鏈接它壞了,但它應該仍然工作。

+0

- 尼斯找到,這讓我想到了正確的方向。查看我的迴應,瞭解我最終使用的內容。 – ryanve 2011-12-24 18:11:59

1

這裏就是我想我會用:

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

如果輸入'linear'或者如果它是從jQuery UI的那麼它將返回。否則它將返回false。如果您通過false作爲.toggle()寬鬆價值,那麼它會默認爲'swing',因此我沒有這樣做 - 因爲沒有必要特別檢查swing。就像這樣:

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

我想,如果你要檢查自定義緩動功能太多,那麼你可以添加一個$.isFunction檢查布爾:

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

而不是返回false我會返回'null' - 遲到評論:) – andlrc 2012-11-20 08:49:23