首页 > 解决方案 > jQuery-confirm 防止在 callerElement.hide() 上滚动

问题描述

我有一个问题,在我隐藏打开确认对话框的按钮元素后,我的页面滚动到顶部。

确认 doalog 关闭后,它会滚动回滚动到调用者元素。如果没有这样的元素,请改为滚动到顶部。我可以阻止那个滚动吗?

我在 js fiddle 中重新创建了我的问题: https ://jsfiddle.net/at6sLy2g/

$('#openDialog').on('click', function(){
  $.confirm({
      buttons: {
          confirm: function () {
            $('#openDialog').hide();
          },
          cancel: function () {
          }
      }
  });
})

标签: javascriptjqueryjquery-confirm

解决方案


添加以下行以确认弹出配置:

$.confirm({
    scrollToPreviousElement: false, // add this line 
    scrollToPreviousElementAnimate: false, // add this line 
    buttons: {
        confirm: function () {
            $('#openDialog').hide();
        },
        cancel: function () {
        }
    }
});

推荐阅读