confusing Leaflet scrollTop on focus

Home Forums MapPress Support confusing Leaflet scrollTop on focus

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #19413


    I’ve got a behaviour of a Leaflet map, that’s strange.

    I have a custom made poi list with a button to center and open the poi(‘s bubble). Everything working fine.

    Unwanted: when the bubble or poi or map gets clicked, the page scrolls to the top, leaving the map half offscreen. Clicking a second time after scrolling back down a bit does not repeat the behaviour, so it seems related to the focus event.

    This happens also anytime when the map gets focus after leaving it.

    I found a most likely related thread on stackoverflow.

    I would highly appreciate an option to programmatically stop this behaviour like e.g. a parameter noscroll in the MappressMap object.

    As I understand the linked solution, there is a critical “moment” to apply a patch to the Leaflet API.
    Since mappress loads the leaflet API and builds the map, I see no good chance to implement this solution myself. Please point me in the right direction, if I am wrong.

    the happy mappres user



    Funny, I never noticed that behavior until you pointed it out.  It seems to be a long-standing a Leaflet bug/feature, and it’s discussed here:

    The best approach is to get Leaflet to patch their behavior.  You can also try this approach from stackoverflow, which has no timing dependency (‘mapp0’ is the first map on the screen):

    jQuery(document).ready(function() {
      mapp0.getMap().getContainer().focus = ()=>{};

    If that doesn’t work, I can add a workaround to MapPress, and it will be included in the next major release.  Please use the contact form to email me for info on testing this functionality.


    Hi Chris,

    thanks for the fast support. I tried your code and as some other tests before it does not help.

    So your fix is wanted here 😀



    Strange, I tried that code and it worked for me, although the one that patches/changes Leaflet did not.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.