jquery animate:一项一项地改变元素的不透明度
知道如何将每个特定元素的不透明度一一设置为最多 16 个目标/元素吗?
这将改变所有元素的不透明度,
$('.block-item').animate({
opacity:0
},500);
请查看此处。
但我希望不透明度逐渐改变。当到达第 16 个元素时就会停止。
这是 html,
<div id="parent_container">
<div class="block-item">1</div>
<div class="block-item">2</div>
<div class="block-item">3</div>
<div class="block-item">4</div>
<div class="block-item">5</div>
<div class="block-item">6</div>
<div class="block-item">7</div>
<div class="block-item">8</div>
<div class="block-item">9</div>
<div class="block-item">10</div>
<div class="block-item">11</div>
<div class="block-item">12</div>
<div class="block-item">13</div>
<div class="block-item">14</div>
<div class="block-item">15</div>
<div class="block-item">16</div>
<div class="block-item">17</div>
<div class="block-item">18</div>
</div>
我推出了这个函数,但它会使任何浏览器崩溃,
function opacity_test(index)
{
$('.block-item').eq( index ).animate({
opacity:0
},500);
setInterval( function() {
opacity_test(index + 1);
}, 1000 );
}
谢谢。
Any idea how to animate the opacity of each certain element one by one up to 16 targets/ elements only?
This will change the opacity of the elements all together,
$('.block-item').animate({
opacity:0
},500);
Have a look here.
But I want the opacity to change one after another. and this will stop when it reaches the 16th element.
Here is the html,
<div id="parent_container">
<div class="block-item">1</div>
<div class="block-item">2</div>
<div class="block-item">3</div>
<div class="block-item">4</div>
<div class="block-item">5</div>
<div class="block-item">6</div>
<div class="block-item">7</div>
<div class="block-item">8</div>
<div class="block-item">9</div>
<div class="block-item">10</div>
<div class="block-item">11</div>
<div class="block-item">12</div>
<div class="block-item">13</div>
<div class="block-item">14</div>
<div class="block-item">15</div>
<div class="block-item">16</div>
<div class="block-item">17</div>
<div class="block-item">18</div>
</div>
I came out this function but it crashes any browser on it,
function opacity_test(index)
{
$('.block-item').eq( index ).animate({
opacity:0
},500);
setInterval( function() {
opacity_test(index + 1);
}, 1000 );
}
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个:
小提琴: http://jsfiddle.net/maniator/VS8tQ/3/
Try this:
Fiddle: http://jsfiddle.net/maniator/VS8tQ/3/
您可以使用
.animate()
的“完成回调”来开始下一个淡入淡出:请参阅 http:// jsfiddle.net/alnitak/3DuTG/
You can use the "completion callback" of
.animate()
to start the next fade:See http://jsfiddle.net/alnitak/3DuTG/
使用回调的选项,并在到达第 16 个元素时停止,您可以使用
.index()
jsfiddle 上的示例
An option using the callback, and to stop when it reaches the 16th element you can use
.index()
Example on jsfiddle