简体   繁体   English

Windows Phone 8 IE scrollTo不起作用

[英]Windows Phone 8 IE scrollTo not working

I have some javascript, I am using to dismiss a screen. 我有一些JavaScript,我正在关闭屏幕。 As part of it, I want the page to scroll to the top, so I am using window.scrollTo(0, 0) which works on android and iphone browsers, but the windows 8 phone is not scrolling... 作为它的一部分,我希望页面滚动到顶部,所以我使用的是window.scrollTo(0, 0) ,它可在android和iphone浏览器上使用,但Windows 8手机无法滚动...

var dismissWelcome;
dismissWelcome = function(e) {
  var welcome;
  if (((e != null ? e.stopPropagation : void 0) != null) && ((e != null ? e.preventDefault : void 0) != null)) {
    e.stopPropagation();
    e.preventDefault();
  }
  welcome = document.getElementById('welcome');
  welcome.style.display = 'none';
  window.scrollTo(0, 0);
};
addEvent('dismiss-welcome', 'touchstart', dismissWelcome);

How can I get window.scrollTo(0, 0) to work on windows 8 phone (and preferably all known devices). 我如何才能在Windows 8手机(最好是所有已知设备)上使用window.scrollTo(0, 0) )。

I put it in a timeout, and it works fine. 我将其设置为超时,并且效果很好。 Must be something to do with the dom object being removed. 必须与被删除的dom对象有关。 There might be other ways around this, but this works fine for me. 可能还有其他方法,但这对我来说很好。

var dismissWelcome;
dismissWelcome = function(e) {
  var welcome;
  if (((e != null ? e.stopPropagation : void 0) != null) && ((e != null ? e.preventDefault : void 0) != null)) {
    e.stopPropagation();
    e.preventDefault();
  }
  welcome = document.getElementById('welcome');
  welcome.style.display = 'none';
  window.scrollTo(0, 0);
  // do it again, after the welcome page has finished being removed...
  setTimeout(function() {
    window.scrollTo(0, 0);
  }, 200);
};
addEvent('dismiss-welcome', 'touchstart', dismissWelcome);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM