javascript - ScrollTop function wont work in Edge - Stack Overflow

I have a function that I call on the onclick event of a button.function ScrollToEditor() {$('html,

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745280930a4620275.html

相关推荐

  • javascript - ScrollTop function wont work in Edge - Stack Overflow

    I have a function that I call on the onclick event of a button.function ScrollToEditor() {$('html,

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信