【发布时间】:2014-04-03 13:50:06
【问题描述】:
我正在关注本教程(已删除链接,因为 SO 上不允许使用 YouTube 视频)。
我不明白为什么横幅不能按原样闪烁,我有 4 张图像我打算让它闪烁。
另外,如果有人确实解决了这个问题,我怎样才能使图像链接到另一个页面,例如,是否像在 HTML 代码中添加 <a href=.......> 一样简单?
HTML:
<script type="text/javascript" src:"jquery.js"></script>
<div id="banner">
<img src="images/banner1.jpg" class="active" />
<img src="images/banner4.jpg" />
<img src="images/banner2.jpg" />
<img src="images/banner3.jpg" />
</div>
javascript/jQuery
> $(document).ready(function () {
setInterval(function () {
//Get current active image
var active = $('#banner .active');
// If there is another image(object) left then make that image next
// If not, go back to the first image of the banner div
if (active.next().length > 0) var next = active.next();
else var next = $('#banner img:first');
//Get the next image ready by modifying the z-index
next.css('z-index', '2');
//Fade out the active image, then
active.fadeOut(1000, function () {
});
//Move the active image to the back of the pile, show it and remove the active class
active.css('z-index', '1').show().removeClass('active');
//Make the next image the active one
next.css('z-index', '3').addClass('active');
});
}, 3000);
});
CSS
#banner {
position: relative;
margin-left: auto;
margin-right: auto;
height: 350px;
width: 950px;
margin-top: 10px;
}
#banner img {
position:absolute;
z-index:1;
}
#banner img.active {
z-index:3;
}
【问题讨论】:
-
src:"jquery.js"应该是src="jquery.js"。 -
已纠正但未修复,是在搜索 jquery 文件吗?我在构建了一半的主页后添加了这个,所以我需要添加一个“jquery.js”文件还是它是如何工作的?
-
您将
jquery.js放在与您的主页相同的位置,该链接将起作用。您的 jQuery 部分还必须有很多}。我会回到教程并找出你哪里出错了。还有一件事,我建议不要使用视频教程与文字相比可能很难理解。 -
如果你让它工作,这就是它的样子DEMO HERE 那就是你的代码在工作。 (我使用不同尺寸的图像只是为了表明它可以正常工作,您可以使用相同的尺寸。)
-
谢谢,它还说第二行到最后一行的语法错误(上面的行