首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Chrome和Internet控制台称“top”是“未定义的”,但Safari和Firefox没有错误

Chrome和Internet控制台称“top”是“未定义的”,但Safari和Firefox没有错误
EN

Stack Overflow用户
提问于 2015-07-21 05:11:01
回答 1查看 151关注 0票数 1

我被这个错误困住了。为什么Internet Explorer 9和Chrome 45会显示这个错误?

顶部未定义

我是不是遗漏了什么?我的一些HTML布局也在Internet 9中受到影响。而且,我也不知道字体系列或div的宽度(百分比)是否会出现这个错误。有什么可以解决这个问题的吗?

代码语言:javascript
复制
var bodyScroll = 0;
$(document).ready(function() {

  bodyScroll = $(window).scrollTop();
  currentP = 0;
  currentP1 = 0;
  currentP2 = 0;
  $(window).scroll(function() {

    scrTop = $(window).scrollTop();
    bodyScroll < scrTop ? currentP = currentP - .8 : currentP = currentP + .8;
    $(".mainContainer, .mobileBanner").css('background-position', "0
 " + currentP + "px");
    if (scrTop > $("#core-services .core-banner").position().top - 400) {
      bodyScroll < scrTop ? currentP1 = currentP1 - .8 : currentP1 = currentP1 + .8;
      $("#core-services .core-banner").css('background-position',
 "0 " + currentP1 + "px");

    }
    if (scrTop > $(".core-contact").position().top - 400) {
      bodyScroll < scrTop ? currentP2 = currentP2 - .8 : currentP2 = currentP2 + .8;
      $(".core-contact").css('background-position', "0 " + currentP2 + "px");

    }
    bodyScroll = scrTop;
  });
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-21 06:06:26

下面的工作为我在Chrome 43中没有错误(我即将测试的互联网,更好的浏览器9)

编辑:它在9上工作。所以我怀疑错误不在你发布的代码中。您需要构建一个最小的示例来重现错误,方法是从页面中删除除相关代码之外的其他内容,然后发布一个JSFiddle或堆栈溢出的本机代码内容(如这篇文章),然后人们可以在9中尝试并确认问题。这只是正常的调试。你会明白的。Internet 9和Chrome应该支持这个位置().top。

编辑:作为中可能出错的例子,请检查是否有任何与HTML元素的id同名的全局变量。如果您这样做,可能会触发“兼容性模式”,这将使下降到8模式,后者不支持“文章”html5元素,因此这些元素就不会有"top“例如。

代码语言:javascript
复制
var bodyScroll = 0;
$(document).ready(function() {

  bodyScroll = $(window).scrollTop();
  currentP = 0;
  currentP1 = 0;
  currentP2 = 0;
  $(window).scroll(function() {

    scrTop = $(window).scrollTop();
    bodyScroll < scrTop ? currentP = currentP - .8 : currentP = currentP + .8;
    $(".mainContainer, .mobileBanner").css('background-position', "0 " + currentP + "px");
    if (scrTop > $("#core-services .core-banner").position().top - 400) {
      bodyScroll < scrTop ? currentP1 = currentP1 - .8 : currentP1 = currentP1 + .8;
      $("#core-services .core-banner").css('background-position', "0 " + currentP1 + "px");

    }
    if (scrTop > $(".core-contact").position().top - 400) {
      bodyScroll < scrTop ? currentP2 = currentP2 - .8 : currentP2 = currentP2 + .8;
      $(".core-contact").css('background-position', "0 " + currentP2 + "px");

    }
    bodyScroll = scrTop;
  });
});
代码语言:javascript
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<section id="core-services">
  <div class="core-banner">
    <img src="images/core-services.jpg" class="img-responsive"/>
  </div>
</section>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31530829

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档