jquery,循环遍历div,然后停在最后一个div?
我一直在四处寻找,但还没有找到真正有效的东西。
基本上我们有一个用户单击按钮的插页式页面。我想循环浏览背景图像,例如每个 500 毫秒,然后停在最后一个 div 上。
我已经发现了一些东西,但在最后一个上找不到任何东西?我玩过的那些似乎并没有停止在最后一个,它只是继续运行。
提前致谢!
这是代码,基本上 Slide1 将显示 500 毫秒,Slide2 将显示 500 毫秒,然后停止在 SlideMain 上:
<div id="slideshow">
<div id="slide1" class="active">Slide1</div>
<div id="slide2">Slide2</div>
<div id="slide3">Slide3</div>
<div id="slide4">Slide4</div>
<div id="slide5">Slide5</div>
<div id="slide_main">SlideMain</div>
</div>
I've been searching around, but haven't found something that actually works.
Basically we have an interstitial page that the user clicks a button. I want to loop through background images, say 500ms each, then stop on the last div.
I've found a few things out there, but can't get anything to stop on the last one? The ones I've played with doesn't seem to stop on the last one, it just keeps running.
Thanks in advance!
Here's the code, basically Slide1 will show up for 500ms, Slide2 for 500ms, then stop on slideMain:
<div id="slideshow">
<div id="slide1" class="active">Slide1</div>
<div id="slide2">Slide2</div>
<div id="slide3">Slide3</div>
<div id="slide4">Slide4</div>
<div id="slide5">Slide5</div>
<div id="slide_main">SlideMain</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您还可以选择父 div 并循环遍历其中包含的所有 div,
这将为 jQuery 选择器提供一个上下文,因此只会查找幻灯片 div 中的 div,而不是整个 DOM。
You can also select the parent div and loop through all the divs contained within
This will give the jQuery selector a context and thus will only look for divs within the slideshow div, rather than the whole DOM.
根据您的标记,看起来您正在做某种幻灯片/循环的事情。任何好的幻灯片/循环插件都会在某些事情发生时具有回调函数,因此您应该很容易地说出类似的话:
显然,类和回调函数的名称会因插件而异。
Based on your markup it looks like your doing some sort of slideshow/cycle thing. Any good slideshow/cycle plugin will have callback functions for when certain things happen, so you should pretty easily be able to say something like:
Obviously names of classes and callback functions will vary from plugin to plugin.
非常简单,只需循环遍历所有
即可
Pretty simple just loop thru all the
<div>
's