Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

One solution to prevent the LeafletJS page from jumping when a layer is clicked is to use event.preventDefault() in the event listener for the click event. This will prevent the default behavior of the click event, which is to follow any links or jump to anchor points on the page. Instead, the map will respond to the click event without altering the page's scroll position.

For example:

// Add a click event listener to a layer
layer.on('click', function(event) {
  // Prevent the default behavior of the click event
  event.preventDefault();
  // Do something else with the click event, such as opening a modal window
});