Jquery 未捕获类型错误:无法读取属性';每个';未定义的

Jquery 未捕获类型错误:无法读取属性';每个';未定义的,jquery,html,scroll,fade,Jquery,Html,Scroll,Fade,我得到:Uncaught TypeError:无法读取未定义的属性“each” 在Finview 至少 代码如下: <script> function animateIfInView() { $.each($("content-img"), function(key, value) { if (isElementInViewport($(value))) { $(value).addClass("content-img-in-view"); } else { // (

我得到:Uncaught TypeError:无法读取未定义的属性“each” 在Finview 至少

代码如下:

 <script>
 function animateIfInView() {
 $.each($("content-img"), function(key, value) {
 if (isElementInViewport($(value))) {
 $(value).addClass("content-img-in-view");
 } else {
  // (Optional) Fade out when out of view
  $(value).removeClass("content-img-in-view");
  }
  });
  }

  // http://stackoverflow.com/a/7557433/5628
   function isElementInViewport(el) {
    //special bonus for those using jQuery
  if (typeof jQuery === "function" && el instanceof jQuery) {
  el = el[0];
  }

  var rect = el.getBoundingClientRect();

  return (
  rect.top >= 0 &&
  rect.left >= 0 &&
  rect.bottom <=
  (window.innerHeight ||
  document.documentElement.clientHeight) /*or $(window).height() */ &&
  rect.right <=
  (window.innerWidth ||
  document.documentElement.clientWidth) /*or $(window).width() */
  );
  }
  </script>

函数animateFinView(){
$。每个($(“内容img”)函数(键、值){
if(IsElementViewPort($(值))){
$(value).addClass(“视图中的内容img”);
}否则{
//(可选)在看不见时淡出
$(value).removeClass(“视图中的内容img”);
}
});
}
// http://stackoverflow.com/a/7557433/5628
函数IsElementViewPort(el){
//为使用jQuery的用户提供特别奖励
if(jQuery的类型==“函数”&&el实例jQuery){
el=el[0];
}
var rect=el.getBoundingClientRect();
返回(
rect.top>=0&&
rect.left>=0&&

rect.bottom我建议如下:

function animateIfInView() {
  $(".content-img").each(function(key, elem) {
    if (isElementInViewport($(elem))) {
      $(elem).toggleClass("content-img-in-view");
    }
  });
}
类选择器使用
$(“.className”)
,其中代码缺少
。此外,如果使用元素,建议使用
.each()
而不是
$。each()
建议用于数组和对象

jQuery.each(array/object,callback_function);
需要第一个参数作为数组或对象。请阅读文档 。我建议使用
var obj=$(文档)。找到(“.content img”);
然后使用 作为


这:
$(.content-img”)
是一个不正确的选择器。这是用于ID还是类?我还建议使用
$(.content-img”)。each()
这是一个类,因此该页面上的每个图像在滚动时都会进行相同的淡入淡入处理谢谢,我会在工作电脑上试用,如果它因某种原因工作正常,我会让你知道并投票给你(不知道为什么你的代码应该工作,只要你使用正确的选择器:
。content img
你能检查一下这里的页面吗:,也许你能看到哪里出了问题,提前谢谢man@nellement我立即发现了两个需要解决的语法错误。SyntaxError:missing;before语句snaak-2-11:474:37&SyntaxError:期待表达,得到‘你能告诉我更多的代码,我的广告上面的原始职位,使这项工作吗?提前感谢
$.each(obj,function(key,value){
//your code goes here
});