jquery - 无法读取未定义的属性 'left'

标签 jquery web scroll scrollto

试图找出 chrome 抛出错误的原因

"Uncaught TypeError: Cannot read property 'left' of undefined"

尽管#explorenav 效果很好,但#experiencenav 似乎不起作用。我错过了什么吗?

JS 代码:

$('.nav li#explorenav a').click(function(){
    $('body').animate({scrollLeft: $("#explore").offset().left-15}, 1000, function(){
        $(this).parent().addClass('active');
    });

    return false;
});

$('.nav li#experiencenav a').click(function(){
    $('body').animate({scrollLeft: $("#experience").offset().left-15}, 1200, function(){
        $(this).parent().addClass('active');
    });

    return false;
});

HTML 代码:

<div id="explore">
    <div class="Features">
        <div class="Feature1" title="The Active Park Assist feature can find parking spaces for you and help manoeuvre your car into them, as if by magic.">
            &nbsp;
        </div>
        <div class="Feature2" title="The luxurious and athletic Interior has sports front seats with red stitching and belts, making you wish the journey never ended">
            &nbsp;
        </div>
        <div class="Feature3" title="With Collision Prevention Assist and Attention Assist you can rest assured that you’ll get to wherever you’re going, safely.">
            &nbsp;
        </div>
    </div>
</div>

<div id="experience">
    <div class="Video">
        <iframe id="Youtube" width="650" height="366" src="http://www.youtube.com/embed/XS6S8qSMvBE?wmode=opaque" frameborder="0" wmode="transparent" allowfullscreen  ALLOWTRANSPARENCY="true"></iframe>

        <button class="prev">&nbsp;</button>
        <button class="next">&nbsp;</button>
        <div class="VideoControls">
            <ul class="Vid">
                <li id="01" class="Video1" onClick="_gaq.push(['_trackEvent', 'Pulse', 'onClick', 'ENGLISH']);">
                    &nbsp;
                </li>
                <li id="02" class="Video2" onClick="_gaq.push(['_trackEvent', 'Performance', 'onClick', 'ENGLISH']);">
                    &nbsp;
                </li>
                <li id="03" class="Video3" onClick="_gaq.push(['_trackEvent', 'Parking Assist', 'onClick', 'ENGLISH']);">
                    &nbsp;
                </li>
                <li id="04" class="Video4" onClick="_gaq.push(['_trackEvent', 'Flow', 'onClick', 'ENGLISH']);">
                    &nbsp;
                </li>
                <li id="05" class="Video5" onClick="_gaq.push(['_trackEvent', 'Spike', 'onClick', 'ENGLISH']);">
                    &nbsp;
                </li>
                <li id="06" class="Video6" onClick="_gaq.push(['_trackEvent', 'Product film', 'onClick', 'ENGLISH']);">
                    &nbsp;
                </li>
            </ul>
        </div>
    </div>
</div>

最佳答案

在您的网站脚本中,您有以下代码:

$('.nav li#experiencenav a').click(function(){
     $('body').animate({scrollLeft: $("#experience .EmptyPage").offset().left-20}, 1200, function(){
      $(this).parent().addClass('active');
      $('li#homenav, li#discovernav, li#explorenav, li#downloadnav').removeClass('active');
     });
      return false;
    });

并且找不到元素$("#experience .EmptyPage")。但是您的 #explore div 中有这样的 div:

<div class="EmptyPage">
 &nbsp;
</div>

这就是为什么您的代码适用于探索链接,但不适用于其他链接。

关于jquery - 无法读取未定义的属性 'left',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15545226/

相关文章:

android - 是否可以支持旧 API 级别的 setScrollY() (ScrollView API 14) 之类的函数?

javascript - 从数组中提取的列表中缺少值

javascript - 如果单元格中的值传递给 JavaScript,则以颜色显示表格的列

javascript - jQuery 计算一个 div 中的换行符数?

css - SVG 作为超大网站背景

listview - 在 Flutter 中,如何制作一个顶部和底部都是无限的 ListView ?

javascript - 导航 : Setting page Anchor tag (javascript or css)

javascript - 我的 toFixed();不工作

networking - 当 Dup Ack 到达时,TCP 是否会增加其拥塞窗口?

mysql - 如果字段值为 0 或 1,如何选择 sum?