jquery - 我如何使用 jquery 显示和隐藏这个加载栏

标签 jquery css animation loading

我想在我的网站上使用这个加载动画,但是当我使用 jquery show()hide() 时,我没有得到想要的结果。

还有 .css('display', 'block').css('display', 'none') 也没有达到预期的效果。

我假设这是因为 css :not 和 :before 的运行方式,但我的 css 技能不是很好,所以我不确定。

加载动画代码笔: https://codepen.io/MattIn4D/pen/LiKFC

我的代码:

document.onscroll = function() {
    if(document.documentElement.scrollTop + window.innerHeight == document.documentElement.scrollHeight) {
            $('.loading').show();
            $.getJSON('/json.php?prefetch', function(data) {
                    //json sorting here.
                });
        $('.loading').hide();
        }
    }

最佳答案

回调 $('.loading').hide(); 在您的 getJson 函数中。这样你的加载 gif 将在 getjson 函数运行时隐藏。您还可以检查您的数据并根据条件隐藏加载 gif。

document.onscroll = function() {
    if(document.documentElement.scrollTop + window.innerHeight == document.documentElement.scrollHeight) {
            $('.loading').show();
            $.getJSON('/json.php?prefetch', function(data) {
                    //json sorting here.
                   $('.loading').hide();
                });

        }
    }

关于jquery - 我如何使用 jquery 显示和隐藏这个加载栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48378685/

相关文章:

animation - 动画 SVG 路径 d=... 没有描边的坐标

php - 在下拉框中进行选择后显示文本值

jquery - 在每次 Jquery Ajax 命中之前检查 Session

javascript - 如果单击子元素,则不要更改父元素的颜色

html - 导航栏下的新内容在关闭 </nav></div> 标签后结束在导航栏内

iphone - Cocos2D 获取 CCAction 的进展

android - 动画 child 回到原来的位置

Javascript 字符串验证。如何在字符串中只写一次字符并且只在开头?

javascript - 从一个下拉列表中选择一个选项填充其他输入字段

javascript - Angular + Bootstrap : Table designing