javascript - SetInterval 在 Firefox 中看不到函数

标签 javascript firefox setinterval

我对 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/

相关文章:

firefox - PouchDB 将其数据存储在笔记本电脑的什么位置?

javascript - D3,具有 setInterval 和clearInterval 以及事件处理程序的 javascript 函数范围

javascript - 随着时间的推移增加 setInterval 时间?

Javascript -clearInterval() 不起作用

javascript - 如何将 2 个或更多参数从 HTML 输入传递到 Javascript 函数

javascript - 带有 html 注入(inject)的 Firefox 问题

asp.net - 页面加载在 Firefox 上触发两次

JavaScript:利用 setInterval() 调用类方法

javascript - jQuery 中 IMG URL 文件夹位置的拇指旋转器

javascript - 捕获浏览器事件