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 🙏

© 2024 – Pkg Stats / Ryan Hefner

leaflet.smooth_marker_bouncing

v3.0.3

Published

Smooth animation of marker bouncing for Leaflet.

Downloads

1,749

Readme

Leaflet.SmoothMarkerBouncing

npm CI Coverage Status

Plugin for Leaflet that will make you markers bounce!

It provides smooth, lightweight and customizable animation of marker bouncing. Allows the bouncing of multiple markers on the map, without loss of performance.

Older browsers

Starting from version v3.0.0, plugin is based on CSS3 keyframes to make animation. If you need support older browsers, it will be better to stick to v2.0.x.

Demo

Check out the demo.

Usage

Add Javascript file on your page:

<script type="text/javascript"
        src="https://cdn.jsdelivr.net/gh/hosuaby/[email protected]/dist/bundle.js"
        crossorigin="anonymous"></script>

Or install it as npm module:

npm install leaflet.smooth_marker_bouncing

Plugin provides additional methods to Marker:

/* Methods of L.Marker class */
L.Marker.setBouncingOptions({..}); // sets options of bouncing of all markers
L.Marker.getBouncingMarkers();     // gets all bouncing markers
L.Marker.stopAllBouncingMarkers(); // asks all markers to stop bouncing

/* Methods of marker instances */
const marker = L.marker([lat, lng]);
marker.setBouncingOptions({..});   // sets options of bouncing for this marker
marker.isBouncing();               // checks if marker is bouncing
marker.bounce();                   // starts the bouncing
marker.bounce(n);                  // makes marker bounce "n" times
marker.stopBouncing();             // stops bouncing of the marker
marker.toggleBouncing();           // starts/stops bouncing of the marker

Plugin respects fluent API. All marker instance methods (except isBouncing) return the marker object.
Some usage examples:

/* Create a marker and make it bounce immediately */
const marker = L.marker([lat, lng]).addTo(map).bounce();

/* Create a marker and make it bounce 2 times when clicked.
 * Do something when the bouncing is stopped, like open a popup.
 */
const marker = L.marker([lat, lng])
    .addTo(map)
    .on('click', function() {
        this.bounce(2) // bounce 2 times
        .on('bounceend',function() {
            console.log('bounce end');
        }); 
    });

/* Create a marker and set its bouncing options.
 * Bouncing can be started/stopped by the click on the marker.
 */
const marker = L.marker([lat, lng])
    .setBouncingOptions({
        bounceHeight : 60,    // height of the bouncing
        bounceSpeed  : 54,    // bouncing speed coefficient
        exclusive    : true,  // if this marker is bouncing all others must stop
    })
    .addTo(map)
    .on('click', function() {
        this.toggleBouncing();
    });

/* Define options of bouncing for all markers */
L.Marker.setBouncingOptions({
        bounceHeight : 60,   // height of the bouncing
        bounceSpeed  : 54,   // bouncing speed coefficient
});

/* Create 10 markers and each of them will bounce 3 times when clicked */
for (let i = 0; i < 10; i++) {
    const marker = L.marker([lat, lng])
        .addTo(map)
        .on('click', function() {
            this.bounce(3); // bounce 3 times
        });
}

Options of bouncing

You can easily customize bouncing animation supplying options in method setBouncingOptions. This method available on the marker class L.Marker and on each of marker instances.
It's highly recommended define options for all markers via L.Marker.setBouncingOptions instead of define them on each marker individually. The animation performance highly increases when all markers have the same options.
Method setBouncingOptions accepts an object with options as parameters. Animation can be customized with following properties:

  • bounceHeight - how high marker will bounce (px), default: 15
  • contractHeight - how much marker will contract when it touches the ground (px), default: 12
  • bounceSpeed - bouncing speed coefficient, value used to calculate the speed of bounce animation, more it becomes high, more animation becomes slow, default: 52
  • contractSpeed - contracting speed coefficient, default: 52
  • shadowAngle - shadow inclination angle, if set to null shadow animation disabled (radians), default: -𝜋÷4
  • elastic - activate contract animation when marker touches the ground, default: true
  • exclusive - when it's true, stops the bouncing of other markers when this one starts to bounce. If another marker start to bounce after, this marker stops. default: false

Events

|Event|Description| |---|---| |bounceend|Fired when the animation is done|