循环 Div 和缩略图
我希望有人能拯救我!我正在尝试为我的页面创建一个(希望如此)简单的旋转横幅。我有 7 个包含照片和文本的 div,它们如下:
<div id="content-1">Sample text</div>
<div id="content-2">Sample text</div>
<div id="content-3">Sample text</div>
<div id="content-4">Sample text</div>
<div id="content-5">Sample text</div>
<div id="content-6">Sample text</div>
<div id="content-7">Sample text</div>
在这些 div 下面,我有 7 个相应的 div,它们是缩略图:
<div id="thumb-content-1">Sample text</div>
<div id="thumb-content-2">Sample text</div>
<div id="thumb-content-3">Sample text</div>
<div id="thumb-content-4">Sample text</div>
<div id="thumb-content-5">Sample text</div>
<div id="thumb-content-6">Sample text</div>
<div id="thumb-content-7">Sample text</div>
我想做几件事:
1)每 5 秒循环一次新的 div(所以“ content-1”将显示 5 秒,然后是“content 2”等。
2) 对当前缩略图应用一个名为“cr-rotator”的类。我已经设置了样式。
3)我希望能够在用户将鼠标悬停在主 div 或缩略图 div 上时暂停其旋转。
4)最后,我希望拥有它,这样如果您将鼠标悬停在缩略图上,它就会更改主要内容,然后在鼠标移开时继续循环。举例来说,您将鼠标悬停在“thumb-content-3”上,它将使 div“content-3”可见,然后当您将鼠标移开时,它将继续循环。
我知道这里有很多需求,我提前感谢任何可以帮助我的人。我已经获得了一个脚本来循环浏览主图像,但我不确定如何实现其余部分:
var divs = $('div[id^="content-"]').hide(),
i = 0;
(function cycle() {
divs.eq(i).fadeIn(200)
.delay(3000)
.fadeOut(200, cycle);
i = ++i % divs.length; // increment i,
// and reset to 0 when it equals divs.length
})();
非常感谢任何可以帮助我的人。
I'm hoping someone can save my me! I'm trying to create a (hopefully) simple rotating banner for my page. I have 7 divs that contain photos and text, they are as follows:
<div id="content-1">Sample text</div>
<div id="content-2">Sample text</div>
<div id="content-3">Sample text</div>
<div id="content-4">Sample text</div>
<div id="content-5">Sample text</div>
<div id="content-6">Sample text</div>
<div id="content-7">Sample text</div>
And below those divs I have 7 corresponding divs that are thumbnails:
<div id="thumb-content-1">Sample text</div>
<div id="thumb-content-2">Sample text</div>
<div id="thumb-content-3">Sample text</div>
<div id="thumb-content-4">Sample text</div>
<div id="thumb-content-5">Sample text</div>
<div id="thumb-content-6">Sample text</div>
<div id="thumb-content-7">Sample text</div>
I would like to do a few things:
1) Every 5 seconds cycle through a new div (so "content-1" would display for 5 seconds, then "content 2" etc.
2) Apply a class to the current thumbnail called "cr-rotator". I have the style already setup.
3) I would like to be able to pause it from rotating when a user hovers over either the main div or thumbnail div.
4) Lastly, I would like to have it so that if you hover over a thumbnail it would change the main content, then continue cycling when you mouse off. So say for example you hover over 'thumb-content-3' it will make the div 'content-3' visible and then when you mouse out it will continue cycling.
I understand there is a lot demanded here and I thank in advance anyone who can help me out. I have been provided a script to cycle through the main images but I'm not sure how to implement the rest:
var divs = $('div[id^="content-"]').hide(),
i = 0;
(function cycle() {
divs.eq(i).fadeIn(200)
.delay(3000)
.fadeOut(200, cycle);
i = ++i % divs.length; // increment i,
// and reset to 0 when it equals divs.length
})();
Thank you so much to anyone that can help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
淡入淡出旋转器 - jsBin 上的演示
jQ代码:
Fade rotator - Demo on jsBin
And the jQ code:
实现所需功能的最简单方法是使用 Malsup 的 Cycle 插件。转到 http://jquery.malsup.com/cycle/ 并下载脚本,然后查看他提供的记录良好的演示。使用 Cycle 让您有机会利用大量不同的选项,这将让您永远无法手动编写代码。
The simplest way to implement your desired functionality is to use Malsup's Cycle Plugin. Go to http://jquery.malsup.com/cycle/ and download the script, then look at the well-documented demos he's provided. Using Cycle gives you the opportunity to take advantage of a ton of different options which would take you forever to hand code.