分からなくなった時には公式のドキュメントを参照するといいですよ!
Step Function
The second version of .animate() provides a step option — a callback function that is fired at each step of the animation. This function is useful for enabling custom animation types or altering the animation as it is occurring. It accepts two arguments (now and fx), and this is set to the DOM element being animated.
now: the numeric value of the property being animated at each step
fx: a reference to the jQuery.fx prototype object, which contains a number of properties such as elem for the animated element, start and end for the first and last value of the animated property, respectively, and prop for the property being animated.
.animate() | jQuery API Documentation
ということですから、step関数はアニメーションのそれぞれのステップで呼び出される関数で、引数のnowはそのステップ時において変化させる値の数値です。
この場合、fx(というダミー値)を400ミリ秒で0から20に変化させているわけですから、nowは0から20のその時点でのどこかの値が入っていることになります。
もう少し説明をします。
簡単のために1ミリ秒を1ステップとして0から20に変化させるアニメーションだとします。
1ミリ秒目
nowには1が入ってますから
lang
1clip: 'rect('+now+'px '+($(this).width()-now)+'px '+($(this).height()-now)+'px '+now+'px)'
は以下のようになります。
lang
1clip: 'rect(1px '+($(this).width()-1)+'px '+($(this).height()-1)+'px 1px)'
2ミリ秒目
nowには2が入ってますから
lang
1clip: 'rect('+now+'px '+($(this).width()-now)+'px '+($(this).height()-now)+'px '+now+'px)'
は以下のようになります。
lang
1clip: 'rect(2px '+($(this).width()-2)+'px '+($(this).height()-2)+'px 2px)'
...
20ミリ秒目
nowには20が入ってますから最終的には以下のようになります。
lang
1clip: 'rect(20px '+($(this).width()-20)+'px '+($(this).height()-20)+'px 20px)'
実際には、jQuery.fx.interval のデフォルト値が13なので、duration が400ですから、1ステップ目の now は 20*13/400=.65 ぐらいになるんじゃないかと思います。確かめてないですが。
余談ですが、clip: inset を利用した方がすっきりしそうなんですが、それを使ってないのは上手く動かないからなんでしょうかね……?
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2015/02/06 10:43