Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When modal is opening scrolls to the top of the page #124

Closed
romanov opened this issue Jun 17, 2019 · 2 comments
Closed

When modal is opening scrolls to the top of the page #124

romanov opened this issue Jun 17, 2019 · 2 comments
Labels

Comments

@romanov
Copy link

romanov commented Jun 17, 2019

  1. Open modal
  2. Page scrolls to the top.
@qmarcos
Copy link

qmarcos commented Jul 16, 2019

If you manage the click with a custom function and are using a link with an href="#", maybe your link is causing this behaviour. You could prevent it on your click listener. Here is an example:

var modalTrigger = document.querySelector('selector-of-your-link');
var modal = new tingle.modal({});

modalTrigger.addEventListener('click', function(ev) {

    // this line invalidate the behaviour of the link 
    // that is causing scrolling to top
    ev.preventDefault(); 

    modal.setContent('<p>Hello!</p>');
    modal.open();
});

Hope it helps.

@St-Permiakov
Copy link

St-Permiakov commented Sep 4, 2019

Same issue here, but on closing.
For me it is caused by the wrong actions order in "close" method.

document.body.classList.remove('tingle-enabled') <-- this is where position='fixed' removed
window.scrollTo(0, this._scrollPosition) <-- no scrollbar is available due to 'top: -####px', but scrollTo is called
document.body.style.top = null <-- scrollbar appears, but too late

Simple fix — swap "scrollTo" and "top = null"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants