window.scrollTo选项在Microsoft Edge上不起作用 [英] window.scrollTo with options not working on Microsoft Edge
问题描述
我有一个奇怪的问题,我只能在Microsoft浏览器上复制(经过Edge和IE11测试).
I have a strange issue which I can only replicate on Microsoft browsers (Edge and IE11 tested).
<style>
body {
height: 5000px;
width: 5000px;
}
</style>
<p>Click the button to scroll the document window to 1000 pixels.</p>
<button onclick="scrollWin()">Click me to scroll!</button>
<script>
function scrollWin() {
window.scrollTo({
left: 1000,
top: 1000,
behavior:"smooth"
});
}
</script>
此代码正确地将窗口向左和向下滚动1000px,在Chrome和Firefox中行为流畅.但是,在Edge和IE上,它根本不会移动.
This code correctly scrolls the window 1000px to the left and down, with a smooth behaviour in Chrome and Firefox. However, on Edge and IE, it does not move at all.
推荐答案
从字面上看,这可能不是一个正确的答案,但是我已经通过使用以下有用的polyfill解决了这个问题:
Maybe not a true answer in the sense of the word, but I have solved this problem by using this helpful polyfill: https://github.com/iamdustan/smoothscroll which works really well across all browsers.
polyfill的示例页面: http://iamdustan.com/smoothscroll/
Example page for pollyfill: http://iamdustan.com/smoothscroll/
非常感谢作者.
这篇关于window.scrollTo选项在Microsoft Edge上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!