这个'现在'在jquery css函数中是什么意思

时间:2013-02-24 04:48:49

标签: jquery

我是jquery的新手,我在jquery api中遇到过关于animate()函数的问题。即使它完美地工作,我只是想知道它在那里是什么意思以及如何在其他地方实现它。这是示例代码块和URL。提前谢谢。

   step: function( now, fx ){
    $( ".block:gt(0)" ).css( "left", now );
   }

http://api.jquery.com/animate/

http://jsbin.com/ihukob/1/edit

1 个答案:

答案 0 :(得分:1)

您的代码:

step: function( now, fx ){
    $( ".block:gt(0)" ).css( "left", now );
}

now是传递给函数step的参数。您正在使用jquery将元素的left位置设置为作为参数传递的值。

示例:

如果你打电话

step("100px", fx);

然后代码将作为

执行
$( ".block:gt(0)" ).css( "left", "100px" );

<强>更新

这是step的{​​{1}}函数。将为动画的每个步骤调用该函数。

  

步骤类型:Function(Number now,PlainObject fx)一个函数   在动画的每一步之后调用。

会发生什么:

当您设置动画jquery.animate()时,您正在使用步进功能将其他$( ".block:first" )元素移动到左侧。

更新2

block

因为代码是这样的

now: the numeric value of the property being animated at each step

$( ".block:first" ).animate({ left: 100 } 将包含now的{​​{1}}值。