最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ScrollTop function wont work in Edge - Stack Overflow

programmeradmin2浏览0评论

I have a function that I call on the onclick event of a button.

function ScrollToEditor() {
  $('html, body').animate({
    scrollTop: $("#ckeditor_editor").offset().top
  }, 1000);
}
<button id="btnScrollToBottom" class="button right" onclick="ScrollToEditor();" type="button">Scroll</button>

This works in Chrome, Firefox and IE11. However, it does nothing in Edge. There are no console errors and the I have made sure that the function is definitely being called.

Any help here would be appreciated.

I have a function that I call on the onclick event of a button.

function ScrollToEditor() {
  $('html, body').animate({
    scrollTop: $("#ckeditor_editor").offset().top
  }, 1000);
}
<button id="btnScrollToBottom" class="button right" onclick="ScrollToEditor();" type="button">Scroll</button>

This works in Chrome, Firefox and IE11. However, it does nothing in Edge. There are no console errors and the I have made sure that the function is definitely being called.

Any help here would be appreciated.

Share Improve this question edited Nov 22, 2017 at 15:38 Rory McCrossan 338k41 gold badges320 silver badges351 bronze badges asked Nov 22, 2017 at 15:36 SmithySmithy 79110 silver badges30 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

For anyone who may e across this issue as well, the only thing that worked for me was the following function:

function ScrollToEditor() {
   document.getElementById('ckeditor_editor').scrollIntoView();
}

Use pageYOffset instead of scrollTop

Note: pageYOffset is not supported supported below IE 9

I may be late but I had the same problem. I found the solution in the following code:

 function topFunction() {
    document.body.scrollTop = 0; //Zero is the pixels from the top of the screen
    document.documentElement.scrollTop = 0;
}

This worked fine for me. I had the problem with Edge. I hope this will be useful for someone with the same problem.

发布评论

评论列表(0)

  1. 暂无评论