我被这个错误困住了。为什么Internet Explorer 9和Chrome 45会显示这个错误?
顶部未定义
我是不是遗漏了什么?我的一些HTML布局也在Internet 9中受到影响。而且,我也不知道字体系列或div的宽度(百分比)是否会出现这个错误。有什么可以解决这个问题的吗?
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;
});
});发布于 2015-07-21 06:06:26
下面的工作为我在Chrome 43中没有错误(我即将测试的互联网,更好的浏览器9)
编辑:它在9上工作。所以我怀疑错误不在你发布的代码中。您需要构建一个最小的示例来重现错误,方法是从页面中删除除相关代码之外的其他内容,然后发布一个JSFiddle或堆栈溢出的本机代码内容(如这篇文章),然后人们可以在9中尝试并确认问题。这只是正常的调试。你会明白的。Internet 9和Chrome应该支持这个位置().top。
编辑:作为中可能出错的例子,请检查是否有任何与HTML元素的id同名的全局变量。如果您这样做,可能会触发“兼容性模式”,这将使下降到8模式,后者不支持“文章”html5元素,因此这些元素就不会有"top“例如。
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;
});
});<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>
https://stackoverflow.com/questions/31530829
复制相似问题