【问题标题】:The script does not work properly in the browser Internet Explorer. How to fix?该脚本在浏览器 Internet Explorer 中无法正常运行。怎么修?
【发布时间】:2017-02-03 02:55:38
【问题描述】:

欢迎!请帮帮我!该脚本在浏览器 Internet Explorer 中无法正常工作。在滚动过程中,有一个强力的上下拉动方块。怎么修?请帮帮我。非常感谢您的帮助!

$(function() {
var $hor = $("#horizontal");
$("body").css('padding-bottom', $(window).width()*2);
var delta = 0;
$(window).on('scroll', function () {
  var top = $(document).scrollTop();
  var width = $(window).width();
  var lim = $hor.position().top - (delta) - ($(window).height() - $hor.outerHeight()) / 2;
  delta = Math.min(Math.max(top - lim, 0), width * 2);

  $(".horizontal:first", $hor).css({left : delta});
  $(".horizontal:last", $hor).css({left : -(width*2 - delta)});
  $("body").css({'padding-top': delta, 'padding-bottom': width*2 - delta});
});

});
p {
  height: 500px;
}
#horizontal {
	position: relative;
	overflow: hidden;
	width: 100%;
	font-size: 3em;
	margin: 0;
	padding: 0;
	height: 250px;
}
#horizontal .horizontal {
	position: absolute;
	width: 100%;
	left: -100%;
	padding: 20px;
}
#horizontal .horizontal .h_blockquote {
	position: relative;
	width: 100%;
	margin: 0 auto;
	font-size: 24px;
	line-height: 1.3em;
	color: #000;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>test</p>
<div id="horizontal">
<div class="horizontal">
<div class="h_blockquote">
<div class="h_blockquote_wrap">The script does not work properly in the browser Internet Explorer. The script does not work properly in the browser Internet Explorer.</div>
</div>
</div>
<div class="horizontal">
<div class="h_blockquote">
<div class="h_blockquote_wrap">The script does not work properly in the browser Internet Explorer. The script does not work properly in the browser Internet Explorer.</div>
</div>
</div>
</div>
<p>test</p>

【问题讨论】:

  • 我们不知道 “无法正常工作” 的具体含义,也不知道您在哪些版本的 Internet Explorer 中进行了测试
  • 在所有版本的 Internet Explorer 浏览器中,当滚动块 #horizo​​ntal 并开始整个页面“上下跳跃”。
  • 嗨,它是一个旧的错误,但有一个使用 jquery 滚动插件的解决方法,您可以阅读所有相关信息并在此处查看详细信息 github.com/noraesae/perfect-scrollbar/issues/160 并在此处修复 manos.malihu.gr/jquery-custom-content-scroller
  • 但是如果你使用侧边栏滚动页面,脚本就可以工作了。
  • 没有人用IE了。如果您支持 IE,那么人们会在您的应用程序中使用它,并且更多人使用 IE = 网络尽头。所以不要修复????对于 IE,请 ????

标签: javascript jquery internet-explorer browser scroll


【解决方案1】:

您不能依赖scroll 在旧浏览器或使用 jQuery 时顺利地触发

问题在于允许在滚动时触发的事件将其取消,因此浏览器必须在出现滚动页面之前完成事件脚本 - 如果这花费的时间过长,滚动似乎会卡住或挂起。

在您的脚本中,您正在调用诸如 .width().outerHeight() 之类的 jQuery 方法,这些方法包含在等待 DOM 回流的 underlying methods。它们很慢,不是特别慢,但足够慢,滚动动画可能会出现掉帧或结巴等待它们。您还会更改定位,这也会导致回流。

现代浏览器有一个新功能来处理这个问题:passive event listeners - 因为被动侦听器无法取消事件,浏览器不必担心等待它们。 jQuery still doesn't support them,所以建议不要使用 jQuery 来处理滚动事件。

然而,这些都不适用于 IE - IE 对这个问题的解决方案是稍微debounce 事件。快速连续的多个滚动将被堆叠并且仅周期性地触发,并且 DOM 回流更改可能导致它部分在之前和部分之后触发。如果您拖动滑块,您不会真正注意到,但是当它赶上时,使用滚轮滚动似乎会突然出现。

我会尝试以下方法:

  • 将所有在滚动事件之间不变的大小检查移到滚动之外。

  • 使用CSS transform: translate 更改要完成的定位,因为它使用显卡进行计算。

【讨论】:

  • 这个问题不仅仅出现在旧的浏览器中。甚至在最新版本的 IE 中。
  • @LADYX 最新版本的 IE 是旧版。 MS 不再开发 IE,IE11 是最后一个版本。自 Windows 10 推出以来,它已经过时了,微软切换到 Edge 作为他们当前/实时浏览器。他们将在 2025 年左右之前修补 IE11 中的安全漏洞,但除此之外,它已经死了 - 仅适用于传统公司和未修补的桌面。
  • @LADYX 不要相信我的话。 Chris Jackson(这类事情的 MS 领导)said that IE 11 is "a dead end"
  • @LADYX 同时,被动事件监听器位于preview for Edge and supported by everyone else,当前浏览器正在努力支持 ES2017 和大量新 API,而 IE11 仍停留在 2013 年。
猜你喜欢
  • 1970-01-01
  • 2011-05-23
  • 1970-01-01
  • 1970-01-01
  • 2020-06-10
  • 1970-01-01
  • 2012-08-12
  • 2012-11-12
  • 1970-01-01
相关资源
最近更新 更多