jQuery图片幻灯片显示bug
jQuery photo slide show bug
我正在使用一些优秀的代码从http://www.queness.com/post/1450/jquery-photo-slide-show-with-slick-caption-tutorial-revisited的照片幻灯片。
这个幻灯片放映库的工作方式是在一个UL中有多个列表项,每个列表项中都有一个图像。依次有一个列表项具有.show类,这将改变该列表项的CSS,因此不透明设置为1。使其可见。计时器确定列表项何时更改,因此层次结构中的下一个列表项具有.show。一旦到达列表的最后一项,它就返回到第一个项。
我的代码的问题是,当页面第一次加载时,第一个图像在切换到第二个图像之前短暂显示。在此之后,幻灯片放映将正常运行。
用粗体表示重要的代码行。首先,我使用jquery将.class赋值给第一个列表项。黑体显示的第二行代码是一个条件语句。如果没有图像带有.show,则将其分配给第一个列表项。这是代码没有按预期工作的时候。
$(document).ready(function (e) {
// Execute the slideShow
slideShow(6000);
thumbInt(); // Assign int to thumbnail list items
gallery();
function clearShowClass() {
setTimeout(timedInterval, 1000);
};
function timedInterval() {
$('ul.slideshow li').not('.show').css("opacity", 0);
clearShowClass();
}
function slideShow(speed) {
//Set the opacity of all images to 0
$('ul.slideshow li').css({
opacity: 0.0
});
//Get the first image and display it (set it to full opacity)
* * $('ul.slideshow li:first').css({
opacity: 1.0
}).addClass('show'); * *
//Get the first thumbnail and change css
$('#footer li:first').addClass('highlight');
//Call the gallery function to run the slideshow
var timer = setInterval('gallery()', speed);
//Pause the slideshow on mouse over content
$('#footer, ul.slideshow').hover(
function () {
clearInterval(timer);
}, function () {
timer = setInterval('gallery()', speed);
});
}
function gallery() {
//if no IMGs have the show class, grab the first image
* *
var current = ($('ul.slideshow li.show') ? $('ul.slideshow li.show') : $('#ul.slideshow li:first')); * *
if (current.queue('fx').length == 0) {
// grab next image and animate code in here
}
//Get next image, if it reached the end of the slideshow, rotate it back to the first image
var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow-caption') ? $('ul.slideshow li:first') : current.next()) : $('ul.slideshow li:first'));
//Set the fade in effect for the next image, show class has higher z-index
next.css({
opacity: 0.0
}).addClass('show').animate({
opacity: 4.0
}, 1000);
// Hide the current image
current.animate({
opacity: 0.0
}, 1000).removeClass('show');
//if no thumbnails have the highlight class, grab the first thumbnail
var currentThumb = ($('#footer li.highlight') ? $('#footer li.highlight') : $('#footer li:first'));
var nextThumb = ($('#footer li:last').hasClass('highlight')) ? $('#footer li:nth-child(1)') : $('#footer li.highlight').next($('#footer li'));
nextThumb.addClass('highlight');
currentThumb.removeClass('highlight');
}
任何关于如何解决这个问题的建议都是非常欢迎的。
尼克我觉得有点傻,但我已经找出了我的代码的问题。您会注意到,当文档准备好时,我已经调用了gallery函数。我还在幻灯片函数中调用了gallery函数
因此,当页面加载时,画廊函数被调用两次,然后它将正常运行。Gallery只需要在slideshow函数中调用。
尼克相关文章:
- 从桌面读取python文件时高亮显示代码
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- 如何在生成下载文件时显示加载动画
- React重新渲染但未显示正确的组件
- nodejs-expressjs上传图像并显示它们
- 使用JSP从服务器检索和显示图像
- 音频控件在mouseover上显示,在mouseout上淡出
- 让文本输入幻灯片显示输入时的新文本输入?然后向后滑动
- 使用电话间隙在Android应用程序中显示SQL Lite的数据
- 显示5秒后隐藏潜水
- 画廊图像未显示
- 不显示带有本地json文件数据的谷歌地图脚本
- 如何将json数据显示为html
- Dimplejs Bug.当序列不为null时,行不会显示
- Jquery AJAX工作,但显示的消息有bug
- Bug缩放图表linkClasses不显示链接
- jQuery图片幻灯片显示bug
- 奇怪的jQuery单选按钮显示/隐藏bug
- 图表-我的旧数据有时显示,bug
- 我的javascript显示代码有个奇怪的bug