jQuery幻灯片库图像连续显示两次
我试图弄明白为什么当我的jQuery幻灯片库在图像和标题之间循环时,第一块信息(图像、标题)会在循环中连续显示两次。每个后续循环都会正确地交替图像jQuery幻灯片库图像连续显示两次,jquery,html,css,gallery,slideshow,Jquery,Html,Css,Gallery,Slideshow,我试图弄明白为什么当我的jQuery幻灯片库在图像和标题之间循环时,第一块信息(图像、标题)会在循环中连续显示两次。每个后续循环都会正确地交替图像 <script type="text/javascript" src="js/jquery-1.3.1.min.js"></script> <script type="text/javascript"> $(document).ready(function() { //Execut
<script type="text/javascript" src="js/jquery-1.3.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
//Execute the slideShow
slideShow();
});
function slideShow() {
//Set the opacity of all images to 0
$('#gallery a').css({opacity: 0.0});
//Get the first image and display it (set it to full opacity)
$('#gallery a:first').css({opacity: 1.0});
//Set the caption background to semi-transparent
$('#gallery .caption').css({opacity: 0.7});
//Resize the width of the caption according to the image width
$('#gallery .caption').css({width: $('#gallery a').find('img').css('width')});
//Get the caption of the first image from REL attribute and display it
$('#gallery .cont').html($('#gallery a:first').find('img').attr('rel'))
.animate({opacity: 0.7}, 400);
//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
setInterval('gallery()',5000);
}
function gallery() {
//if no IMGs have the show class, grab the first image
var current = ($('#gallery a.show') ? $('#gallery a.show') : $('#gallery a:first'));
//Get next image, if it reached the end of the slideshow, rotate it back to the firstimage
var next = ((current.next().length) ? ((current.next().hasClass('caption'))?$('#gallery a:first') :current.next()) : $('#gallery a:first'));
//Get next image caption
var caption = next.find('img').attr('rel');
//Set the fade in effect for the next image, show class has higher z-index
next.css({opacity: 0.0})
.addClass('show')
.animate({opacity: 1.0}, 1000);
//Hide the current image
current.animate({opacity: 0.0}, 1000)
.removeClass('show');
//Set the opacity to 0 and height to 1px
$('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });
//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
$('#gallery .caption').animate({opacity: 0.7},10 ).animate({height: '60px'},500 );
//Display the content
$('#gallery .content').html(caption);
}
</script>
<style type="text/css">
.clear {
clear:both;
}
#gallery {
position:relative;
height:360px;
}
#gallery a {
float:left;
position:absolute;
}
#gallery a img {
border:none;
}
#gallery a.show {
z-index:500;
}
#gallery .caption {
z-index:600;
background-color:#000;
color:#ffffff;
height:60px;
width:100%;
position:absolute;
bottom:0;
}
#gallery .caption .content {
margin:5px;
}
#gallery .caption .content h3 {
margin:0;
padding:0;
color:#1DCCEF;
}
</style>
$(文档).ready(函数(){
//执行幻灯片放映
幻灯片();
});
函数幻灯片(){
//将所有图像的不透明度设置为0
$(#gallery a').css({opacity:0.0});
//获取第一个图像并显示它(将其设置为完全不透明度)
$(#gallery a:first').css({opacity:1.0});
//将标题背景设置为半透明
$('#gallery.caption').css({opacity:0.7});
//根据图像宽度调整标题宽度
$('#gallery.caption').css({width:$('#gallery a').find('img').css('width')));
//从REL属性获取第一幅图像的标题并显示它
$('#gallery.cont').html($('#gallery a:first').find('img').attr('rel'))
.animate({opacity:0.7},400);
//调用gallery函数运行幻灯片放映,6000=6秒后更改为下一张图像
setInterval('gallery()',5000);
}
函数库(){
//如果没有IMG拥有show类,则抓取第一张图像
var current=($('画廊a.show')?$('画廊a.show'):$('画廊a:first');
//获取下一个图像,如果它到达幻灯片的末尾,请将其旋转回第一个图像
var next=((current.next().length)?((current.next().hasClass('caption'))?$('a:first'):current.next()):$('a:first');
//获取下一个图像标题
var caption=next.find('img').attr('rel');
//为下一幅图像设置淡入效果,show类具有更高的z索引
css({opacity:0.0})
.addClass('show')
.animate({opacity:1.0},1000);
//隐藏当前图像
动画({opacity:0.0},1000)
.removeClass(“show”);
//将不透明度设置为0,高度设置为1px
$('#gallery.caption')。动画({opacity:0.0},{queue:false,duration:0})。动画({height:1px'},{queue:true,duration:300});
//设置标题动画,不透明度为0.7,高度为100px,这是一种向上滑动的效果
$(#gallery.caption')。动画({opacity:0.7},10)。动画({height:'60px'},500);
//显示内容
$('#gallery.content').html(标题);
}
.清楚{
明确:两者皆有;
}
#画廊{
位置:相对位置;
高度:360px;
}
#画廊a{
浮动:左;
位置:绝对位置;
}
#画廊a img{
边界:无;
}
#展览馆{
z指数:500;
}
#图库.说明{
z指数:600;
背景色:#000;
颜色:#ffffff;
高度:60px;
宽度:100%;
位置:绝对位置;
底部:0;
}
#图库。标题。内容{
保证金:5px;
}
#画廊。标题。内容h3{
保证金:0;
填充:0;
颜色:#1dcef;
}
有什么想法吗?谢谢,-qs问题在这里:
var current=$(“#画廊a.show”)$(“#画廊a.show”):$(“#画廊a:first”)代码>
空列表是真实的,因此即使$(“#gallery a.show”)
与任何内容都不匹配,表达式的计算结果也将始终为$(“#gallery a.show”)
简单的修复方法如下所示:
var current=$('#画廊a.show')。长度$(“#画廊a.show”):$(“#画廊a:first”)代码>
不过,我认为最好添加$(“#gallery a:first”).addClass('show')在slideShow()
中输入code>,然后忘记$(“#gallery a.show”)
不匹配的情况
一把小提琴会很受欢迎[link]棒极了。(……无语……)