Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 淡出不适用于jquery_Javascript_Jquery - Fatal编程技术网

Javascript 淡出不适用于jquery

Javascript 淡出不适用于jquery,javascript,jquery,Javascript,Jquery,我试图在ajax调用完成后淡出一个预加载程序,但该预加载程序没有淡出并引发错误:uncaughttypeerror:preload.fadeOut不是一个函数 下面是我的代码 我在stackoverflow中进行了尝试,但没有取得成果。淡出是一个jQuery方法,但是document.getElementsByClassName(…)[0]返回一个HTML元素。不能在HtmleElements上使用jQuery方法。应该避免混合使用普通javascript和jQuery。因此,您需要使用jQue

我试图在ajax调用完成后淡出一个预加载程序,但该预加载程序没有淡出并引发错误:
uncaughttypeerror:preload.fadeOut不是一个函数

下面是我的代码
我在stackoverflow中进行了尝试,但没有取得成果。

淡出是一个jQuery方法,但是document.getElementsByClassName(…)[0]返回一个HTML元素。不能在HtmleElements上使用jQuery方法。应该避免混合使用普通javascript和jQuery。因此,您需要使用jQuery来选择元素

$('.spinner').fadeOut();

您没有在此处使用jQuery:

document.getElementsByClassName('spinner')[0];
那是香草JS。您需要使用:

var preloader = $(".spinner");
相反,请使用库


通过使用纯javascript:

var preloader = document.getElementsByClassName('spinner');
   for(let fadeElement of preloader){
    var fadeEffect = setInterval(function () {
    if (!fadeElement.style.opacity) {
        fadeElement.style.opacity = 1;
    }
    if (fadeElement.style.opacity > 0) {
        fadeElement.style.opacity -= 0.1;
    } else {
        clearInterval(fadeEffect);
    }
  }, 200);
}

$('.spinnter').first().fadeOut()
var preloader = document.getElementsByClassName('spinner');
   for(let fadeElement of preloader){
    var fadeEffect = setInterval(function () {
    if (!fadeElement.style.opacity) {
        fadeElement.style.opacity = 1;
    }
    if (fadeElement.style.opacity > 0) {
        fadeElement.style.opacity -= 0.1;
    } else {
        clearInterval(fadeEffect);
    }
  }, 200);
}