我对 JavaScript 还很陌生,所以如果这是一个愚蠢的问题,请原谅我。我使用下面的代码将一张图像滑到屏幕上,并让另外 2 张图像依次出现。这适用于 Chrome 和 IE 7-9。不幸的是,在 Firefox 上我收到一条错误消息:
move is not defined [ mover = setInterval(move, 1000); ]
我的代码:
//define variables
var mover = 0
var bubble1move = 0
var bubble2move = 0
if(mover != 0)
{//interval is finished
function move ()
{
console.log("moving")
clearInterval(mover)
var moving_img = document.getElementById("i_sliding_image")
var left = 0
function frame()
{
left -= 2 // update parameters
moving_img.style.left = left + 'px'// show frame
if (left == -274) // check finish condition
{
clearInterval(id)
bubble1move = setInterval(function() {bubble1()}, 2000);
}
}
var id = setInterval(frame, 10) // draw every 10ms
}
}
if(bubble1move != 0)
{//interval is finished
function bubble1()
{
clearInterval(bubble1move);
document.getElementById("img-bubble1").style.zIndex = "1";
bubble2move = setInterval(function() {bubble2()}, 2000);
}
}
if(bubble2move != 0)
{//interval is finished
function bubble2()
{
clearInterval(bubble2move)
var vBubble2 = document.getElementById("img-bubble2").style
vBubble2.zIndex = "1";
}
}
window.onload = function initialiser()
{
mover = setInterval(move, 1000);//initial time to animation
}
所有 getElementByIds 都获取包含图像的 div 标签。
感谢您的宝贵时间。
最佳答案
看起来您正在将 js 开头的 mover 变量初始化为 0,并且 if 语句仅在 mover != 0
时声明该函数。初始化 mover = 1;
或将函数置于 if 语句之外(推荐)。您只是想在 move()
存在之前调用它
关于javascript - SetInterval 在 Firefox 中看不到函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13604099/