jQueryが読み込まれていてもVelocityでVelocity.jsを使う
Velocity.jsはjQueryが読み込まれていないときはVelocity
で、そうでないときは$.Velocity
とかで使えるんだけど、
ちょっとした処理だけのために常にjQueryを読み込むのも嫌だな、と思ったのでそれのメモ。
jQuery読み込む必要もないほどの処理なのだけど、IE8でも動作する必要があってVelocity.jsはIE8以下の場合jQueryが必要なので条件分岐コメントでjQueryを読み込ませるようにした。
<!--[if lt IE 9.0]>
<script src="jquery-1.11.2.min.js"></script>
<![endif]-->
<script src="velocity.min.js"></script>
Velocityを使うコードの一番上には以下のような感じで書いた。
var Velocity = (!!window.jQuery) ? function() {
return $.Velocity.apply($, arguments);
} : function() {
return window.Velocity(arguments);
};
後者はわざわざ関数で囲む必要はなくて、window.Velocity
をそのまま返せば良かったかもしれない。