2016-02-07 65 views
0

我想更改我的类名我的页面滚动400从feature-animate div的顶部但我收到此错误。未捕获TypeError:无法读取未定义错误的属性'top'

请参阅此链接,我的代码

https://jsbin.com/zafove/edit?html,js,output

Uncaught TypeError: Cannot read property 'top' of undefined error

if(wScroll > $('.feature-animate').offset().top - 400){ 
      $('.feature-animate').each(function(j){ 
       setTimeout(function(){ 
       $('.feature-animate').eq(j).addClass('isShowing'); 
       },100 * (i+1)); 
+1

在这行之前,你可以在你的代码中打印'console.log($('。feature-animate'))'并告诉我它在打印什么? – gurvinder372

+0

未捕获的SyntaxError:意外的令牌ILLEGAL –

+0

是在document.ready事件之后调用此代码吗?调用此代码之前,您的DOM是否已经加载? – gurvinder372

回答

0

该错误消息表示jQuery不会找到.feature-animate类你的HTML节点。首先也是最可能的原因:您的HTML代码中存在拼写错误。确保它看起来像这样:

<div class="feature-animate">...your other html code </div> 

然后它应该工作。顺便说一下:如果你有多个具有相同类名的div容器,$('.feature-animate').offset().top将得到DOM中具有该类的第一个元素的值top

+0

雅我正确地键入类名称。 –

+0

https://jsbin.com/zafove/edit?html,js,output –

0

确保在运行javascript之前feature-animate类的元素已经初始化。一个很好的方法是将其放入$(document).ready()标签中。

0

jQuery无法找到“feature-animate”元素,因为在html中它的写法如下。

<div classs="row feature-animate"> 

(请注意3 'S' 的 '班组长')

应当按照以下内容:

<div class="row feature-animate"> 

(除去多余的“,使其 '阶级')

相关问题