子元素的 jQuery 循环动画
大家下午好!
我有一个浮动 div 的小列表,我想定期突出显示其中一个。基本上我正在尝试显示一个工作流程。使用 jQuery 我希望它:
- 获取父 div 的第一个子级(
#general process
) - 添加一个更改 CSS 的类(即
highlight
) - 添加一个短暂的延迟
- 删除
highlight
类 - 查找下一个子项(如果最后返回到第一个子项)并重复步骤 2-4
我正在尝试解决这个问题,但一直失败。谁能建议实现这种循环动画的最佳方法?预先感谢您的任何建议!!
这是我当前的 HTML 和CSS:
<div id="general_process">
<div class="phase">
<div class="number">1</div>
<h3>Some title</h3>
<p>Content goes here</p>
</div>
<div class="phase">
<div class="number">2</div>
<h3>Some title</h3>
<p>Content goes here</p>
</div>
<div class="phase">
<div class="number">3</div>
<h3>Some title</h3>
<p>Content goes here</p>
</div>
</div>
#general_process {margin: 0; padding: 0; }
#general_process div.phase { float: left; padding: 10px 25px; background: #f9f9f9; width: 254px; border: 1px soild #999999;}
Afternoon all!
I've got a small list of floated divs that I want to highlight one periodically. Basically I'm trying to display a workflow process. Using jQuery I want it to:
- Get the first child of the parent div (
#general process
) - Add a class (i.e
highlight
) which changes the CSS - Add a short delay
- Remove the
highlight
class - Find the next child item (if last to return to the first) and repeat steps 2-4
I'm trying to scratch my way through this but keep failing. Can anyone suggest the best way to achieve this looping animation? Thanks in advance for any suggestions!!
Here is my current HTML & CSS:
<div id="general_process">
<div class="phase">
<div class="number">1</div>
<h3>Some title</h3>
<p>Content goes here</p>
</div>
<div class="phase">
<div class="number">2</div>
<h3>Some title</h3>
<p>Content goes here</p>
</div>
<div class="phase">
<div class="number">3</div>
<h3>Some title</h3>
<p>Content goes here</p>
</div>
</div>
#general_process {margin: 0; padding: 0; }
#general_process div.phase { float: left; padding: 10px 25px; background: #f9f9f9; width: 254px; border: 1px soild #999999;}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们使用闭包来自包含用于跟踪状态的所有变量。
然后我们有一个函数
step()
,它每 3 秒执行一次...它从当前元素中删除该类,如果我们当前位于最后一个元素,则循环回到第一个元素,然后将类添加到目标元素。在此处查看性感演示
We use a closure to self-contain all the variables we use to track the state.
We then have a function
step()
, which executes every 3 seconds... it removes the class from the current element, loops back to the first element if we're currently on the last, and then adds the class to the target element.View a sexy demo here