Chrome 不显示和隐藏加载程序

发布于 2024-12-03 09:29:20 字数 528 浏览 2 评论 0原文

我使用以下函数来显示和隐藏浏览器工作时包含加载图像的 div。它在 Firefox 中运行良好。但在 Chrome 中它不会这样做。即使鼠标不在其上方,屏幕仍保持静态,并且开始函数调用的按钮处于“单击”状态。如果我使用开发人员工具设置断点,那么我会看到 setVisibility() 函数被调用,并且加载器 div 被正确显示和隐藏。

该函数如下所示:

    function setVisibility(id, visibility) {
        if(document.getElementById(id)){
            document.getElementById(id).style.display = visibility;
        }
    }

这是显示/隐藏调用的示例:

    setVisibility("loader", "inline");
    setVisibility("loader", 'none');

有什么想法吗?

I'm using the following function to show and hide divs that contain loading images when the browser is working. It works fine in Firefox. In Chrome though it doesn't do this. The screen remains static with the button that begins the function calls in the "clicked" state, even though the mouse is not over it. If I use the developer tools to set breakpoints then I see the setVisibility() function get called and the loader divs get shown and hidden properly.

The function looks like this:

    function setVisibility(id, visibility) {
        if(document.getElementById(id)){
            document.getElementById(id).style.display = visibility;
        }
    }

And here is an example of a show/hide call:

    setVisibility("loader", "inline");
    setVisibility("loader", 'none');

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤单情人 2024-12-10 09:29:20

我不确定您是否对 jquery 了解很多,但我会包含最新的 jquery 并使用 .show() 和 .hide() 方法...

http://docs.jquery.com/Show

n/m 这个花絮,你用的是display,可见性函数名通过我关了。

I'm not sure if you know much about jquery but I would include the latest jquery and use the .show() and .hide() methods...

http://docs.jquery.com/Show

n/m this tidbit, you're using display, the visibility function name through me off.

美煞众生 2024-12-10 09:29:20

我希望这有帮助

我也遇到了同样的问题,我真的不知道这是怎么发生的,但它可以
使用代码中的小延迟来修复,如下所示。

用此代码替换您的函数

function setVisibility(id, visibility) {
        if(document.getElementById(id)){
            setTimeout(function(){
               document.getElementById(id).style.display = visibility;
            }, 1);
             // please note i have added a delay of 1 millisecond with js timeout function which runs almost same as code with no delay.

        }
    }

i hope this helps

I had the same issue and i really don't know how it's happening, but it can
be fixed using a small delay in code like follows.

RELACE YOUR FUNCTION WITH THIS CODE

function setVisibility(id, visibility) {
        if(document.getElementById(id)){
            setTimeout(function(){
               document.getElementById(id).style.display = visibility;
            }, 1);
             // please note i have added a delay of 1 millisecond with js timeout function which runs almost same as code with no delay.

        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文