npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

leaflet.popup-portal

v1.0.2

Published

Teleports Leaflet popups to a body-level fixed overlay so they render above all controls and UI elements.

Downloads

306

Readme

Leaflet.PopupPortal

npm version License: MIT Leaflet 1.x

Teleports Leaflet popups to a <body>-level fixed overlay so they always render above zoom controls, attribution, and any other UI element.

Live Demo → | Real-World Example → | npm →


The Problem

.leaflet-map-pane applies transform: translate3d() to enable hardware-accelerated panning. The side effect is that it creates a new CSS stacking context, capping the effective z-index of all its descendants. Leaflet's controls (zoomControl, attributionControl, custom panes) live outside this stacking context and always win.

body
└─ .leaflet-container
    ├─ .leaflet-map-pane   ← transform: translate3d() → own stacking context
    │   └─ .leaflet-popup-pane
    │       └─ popup (z-index: 700)  ← trapped, loses to controls
    └─ .leaflet-control-container
        └─ zoom control (z-index: 1000)  ← always on top

The Solution

Leaflet.PopupPortal moves the popup's DOM node to a position:fixed overlay div appended directly to <body>, bypassing the stacking context entirely. Position is kept in sync from popup latlng on move, moveend, zoom, zoomend, viewreset, resize, and window scroll.

All standard Leaflet behaviour — close button, autoPan, popupopen / popupclose events, programmatic openPopup() / closePopup() — remains intact.

body
├─ .leaflet-container        ← map (controls render normally inside)
└─ #leaflet-popup-portal     ← position:fixed; z-index:10000
    └─ popup                 ← renders above everything ✓

Demo

► Open Live Demo

► See Real-World Usage (Political World Map)

► npm Package

The demo shows two identical maps side by side — left without the plugin, right with it. Open a popup near the zoom control to see the difference immediately.


Installation

CDN (jsDelivr)

<!-- after leaflet.js -->
<script src="https://cdn.jsdelivr.net/gh/mwasil/[email protected]/leaflet.popup-portal.js"></script>

npm

npm install leaflet.popup-portal
import L from 'leaflet';
import 'leaflet.popup-portal';   // must come after leaflet

Direct download

Grab leaflet.popup-portal.js and place it after leaflet.js in your page.


Usage

No API needed. Include the file once and every popup on every map gains portal behaviour automatically:

<link  rel="stylesheet" href="leaflet.css" />
<script src="leaflet.js"></script>
<script src="leaflet.popup-portal.js"></script>  <!-- that's it -->

<script>
  var map = L.map('map').setView([51.5, -0.09], 13);
  L.marker([51.5, -0.09])
    .bindPopup('I now render above all controls!')
    .addTo(map);
</script>

Disable per map

Pass popupPortal: false in the map options to opt a specific map instance out:

var map = L.map('map', { popupPortal: false });

How It Works

| Step | What happens | |------|-------------| | popupopen | The popup container is moved to #leaflet-popup-portal, switched to position:fixed, and positioned immediately using map.latLngToContainerPoint(latlng) + popup._getAnchor() plus map container viewport offsets. | | Teleport | The container element is moved to #leaflet-popup-portal — a position:fixed; z-index:10000 div appended to <body>. | | Sync | _updatePosition / _animateZoom are patched to recompute left / top while in portal mode. During zoom animation the plugin uses map._latLngToNewLayerPoint(...) to match Leaflet's animated frame math. | | popupclose | Popup fades out in portal space first, then after PORTAL_FADE_DURATION the node is returned to .leaflet-popup-pane and inline portal styles are reset. A close timer is canceled on reopen to avoid race conditions. |


Compatibility

| Leaflet | Browsers | |---------|----------| | 1.0 – 1.9 | Chrome, Firefox, Safari, Edge (all modern) |

Uses Leaflet events plus a small set of internal methods/properties (_updatePosition, _animateZoom, _latLngToNewLayerPoint, _getMapPanePos, popup internals) to keep portal positioning exact during animations.


Contributing

Bug reports and pull requests welcome at GitHub Issues.


License

MIT © mwasil