Javascript 幻灯片错误(基于 Scriptaculous)
在下面的幻灯片放映代码中,有一个用于按“上一个”和“下一个”链接的功能。 “下一张”效果很好,如果你继续按它,它会循环播放所有幻灯片。
由于某种原因,“上一张”有点混乱 - 它会返回一两张幻灯片,但随后就会变成空白!
你能帮忙吗? 谢谢你!
<script type="text/javascript">
start_slideshow(1, 3, 3000);
var currentSlide = 1;
function start_slideshow(start_frame, end_frame, delay) {
id = setTimeout(switch_slides(start_frame,start_frame,end_frame, delay), delay);
}
function switch_slides(frame, start_frame, end_frame, delay) {
return (function() {
Effect.Fade('slide' + frame, { duration: 1.0 });
if (frame == end_frame) {
frame = start_frame;
currentSlide = frame;
} else {
frame = frame + 1;
currentSlide = frame;
}
Effect.Appear('slide' + frame, { duration: 1.0 });
if (delay == 1000) {
delay = 3000;
}
id = setTimeout(switch_slides(frame, start_frame, end_frame, delay), delay);
})
}
function stop_slideshow() {
clearTimeout(id);
}
function next_slide() {
clearTimeout(id);
Effect.Fade('slide' + currentSlide, { duration: 1.0 });
if (currentSlide == 4) {
currentSlide = 0;
}
currentSlide = currentSlide + 1;
Effect.Appear('slide' + currentSlide, { duration: 1.0 });
id = setTimeout(switch_slides(currentSlide, currentSlide, currentSlide, delay), delay);
}
function previous_slide() {
clearTimeout(id);
if (currentSlide == 0) {
currentSlide = 1;
} else {
Effect.Fade('slide' + currentSlide, { duration: 1.0 });
currentSlide = currentSlide - 1;
Effect.Appear('slide' + currentSlide, { duration: 1.0 });
id = setTimeout(switch_slides(currentSlide, currentSlide, currentSlide, delay), delay);
}
}
</script>
In the slide show code below, there's a function to press "previous" and "next" links. The "next" one works fine, and if you keep pressing it, it cycles through all the slides.
The "previous" one is a bit messed up, for some reason - it will go back a slide or two but then it will just go blank!
Could you please help?
Thank you!
<script type="text/javascript">
start_slideshow(1, 3, 3000);
var currentSlide = 1;
function start_slideshow(start_frame, end_frame, delay) {
id = setTimeout(switch_slides(start_frame,start_frame,end_frame, delay), delay);
}
function switch_slides(frame, start_frame, end_frame, delay) {
return (function() {
Effect.Fade('slide' + frame, { duration: 1.0 });
if (frame == end_frame) {
frame = start_frame;
currentSlide = frame;
} else {
frame = frame + 1;
currentSlide = frame;
}
Effect.Appear('slide' + frame, { duration: 1.0 });
if (delay == 1000) {
delay = 3000;
}
id = setTimeout(switch_slides(frame, start_frame, end_frame, delay), delay);
})
}
function stop_slideshow() {
clearTimeout(id);
}
function next_slide() {
clearTimeout(id);
Effect.Fade('slide' + currentSlide, { duration: 1.0 });
if (currentSlide == 4) {
currentSlide = 0;
}
currentSlide = currentSlide + 1;
Effect.Appear('slide' + currentSlide, { duration: 1.0 });
id = setTimeout(switch_slides(currentSlide, currentSlide, currentSlide, delay), delay);
}
function previous_slide() {
clearTimeout(id);
if (currentSlide == 0) {
currentSlide = 1;
} else {
Effect.Fade('slide' + currentSlide, { duration: 1.0 });
currentSlide = currentSlide - 1;
Effect.Appear('slide' + currentSlide, { duration: 1.0 });
id = setTimeout(switch_slides(currentSlide, currentSlide, currentSlide, delay), delay);
}
}
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到过这样的问题,或者类似的问题。我假设您在当前排队的效果完成之前“快速”单击上一个或下一个按钮。这将导致效果错误,导致给定元素同时应用多个效果。
为了解决这个问题,scriptaculous 使我们能够按顺序排列效果。参考这里的文档:
http://wiki.github.com/madrobby/scriptaculous/effect-queues
本质上,您需要为效果添加范围。因此,在添加持续时间后,您需要添加队列范围。
示例:
这允许我们在按下按钮时取消队列中的任何内容。
这可能会解决你的消隐问题……但也可能不会。无论如何,这些方法需要在您的幻灯片放映中使用;)
如果不能解决问题,请报告,我将进行更多故障排除。
I have run into a problem like this, or similar to this. I am assuming that you are "rapidly" clicking the previous or next button before the effect that is currently queued is finished. This will cause an error with the effects resulting in a given element having more than one affect being applied to it at the same time.
To fix this, scriptaculous gives us the ability to queue effects in order. Reference the docs here:
http://wiki.github.com/madrobby/scriptaculous/effect-queues
Essentially, you need to add a scope to your effects. So after you add your duration, you need to add a queue scope.
Example:
This allows us to cancel anything in the queue when a button is pressed.
This will possibly fix your blanking...but possibly not. Regardless, these methods need to be employed in your slide show ;)
Report back if it doesn't fix it, and I'll do some more troubleshooting.