Jonas Holm
Jonas Holm

Reputation: 53

jQuery-confirm prevent scroll on callerElement.hide()

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 () {
          }
      }
  });
})

Upvotes: 0

Views: 1580

Answers (2)

Edu Garayar
Edu Garayar

Reputation: 1

scrollToPreviousElementAnimate:false

Upvotes: 0

Saranga Mapalagama
Saranga Mapalagama

Reputation: 81

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 () {
        }
    }
});

Upvotes: 2

Related Questions