简体   繁体   中英

Windows Phone 8 IE scrollTo not working

I have some javascript, I am using to dismiss a screen. 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...

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).

I put it in a timeout, and it works fine. Must be something to do with the dom object being removed. 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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