0

I have a problem where my page scroll to the top after i hide the button element which opened the confirm dialog.

After a confirm doalog closes it scroll back scroll to the caller element. If no such element, scroll to the top instead. Can I prevent that scroll?

I've re-created my problem in js fiddle: https://jsfiddle.net/at6sLy2g/

$('#openDialog').on('click', function(){
  $.confirm({
      buttons: {
          confirm: function () {
            $('#openDialog').hide();
          },
          cancel: function () {
          }
      }
  });
})
Jonas Holm
  • 53
  • 1
  • 1
  • 11
  • Here you go: https://jsfiddle.net/khrismuc/nudwqs3m/ –  Mar 20 '19 at 11:20
  • @ChrisG already solved your original problem but I have a question. Why `$('#openDialog').hide();` after you are already scrolling up. If that is desired (I can't think why), make sure you `.show()` the button again when user reaches to bottom of page for a better UX. – Fr0zenFyr Mar 20 '19 at 12:38
  • @ChrisG Thank you very much! Just what I needed :D – Jonas Holm Mar 20 '19 at 13:48
  • @Fr0zenFyr The code i provided was just enough to show the problem, and does reflect my problem, and nothing more. I totally agree that this is bad ux though :P – Jonas Holm Mar 20 '19 at 13:48

2 Answers2

1

Add below lines to confirm popup configuration:

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

scrollToPreviousElementAnimate:false