[英]Slideshow in JavaScript not working
Okay I successfully created a basic slideshow but I wanted to add more effects and such to make it look more realistic. 好的,我成功地创建了一个基本的幻灯片,但是我想添加更多的效果,以使其看起来更逼真。 I am doing some coding but I don't know what is wrong.
我正在做一些编码,但是我不知道出什么问题了。 I end up crashing my
MOZILLA
everytime I run the script. 每次运行脚本时,我最终都会使
MOZILLA
崩溃。 Can anyone help me do this correctly? 谁能帮我正确地做到这一点? And not to mention I don't want any kind of jQuery modification to my code
更不用说我不想对我的代码进行任何形式的jQuery修改
JavaScript 的JavaScript
var img = new Array("a.jpg","b.jpg","c.jpg");
var len = img.length - 1;
var pos = 0;
function slid(e){
pos = pos + e;
if(pos < 0)
{
pos = len;
}
if(pos > len)
{
pos = 0;
}
var a = 1;
var i = 1;
while(i<=50)
{
function op(a) {
a -= 0.02;
if(a < 0)
{
a = 1;
}
document.getElementById("slide").style.opacity = a;
}
i++;
}
document.getElementById("slide").src = img[pos];
return false;
};
and yeah it's not fading(in this case changing opacity) help me on that too? 是的,它不会褪色(在这种情况下,更改不透明度)也可以帮助我吗?
Take a look here: 在这里看看:
while(i<=50)
{
function op(a) {
a -= 0.02;
if(a < 0)
{
a = 1;
}
document.getElementById("slide").style.opacity = a;
}
}
You are not incrementing your 'i' counter variable, resulting in an infinite loop, and hence browser crashing. 您没有增加'i'计数器变量,从而导致无限循环,从而导致浏览器崩溃。 Replace with this:
替换为:
while(i<=50)
{
function op(a) {
a -= 0.02;
if(a < 0)
{
a = 1;
}
document.getElementById("slide").style.opacity = a;
}
i++; //increment the counter variable to prevent an infinite loop
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.