Leaflet.SmoothMarkerBouncing
Plugin for Leaflet that will make you markers bounce!
It provides smooth, lightweight and customisable animation of marker bouncing.
Allows the bouncing of multiple markers on the map, without lose of performance.
Plugin shows it's best performances on the 3D-able modern browsers, using hardware acceleration.
On old browsers plugin provides simplified animation.
Demo
Check out the demo.
Usage
Add Javascript file on your page:
Plugin provides additional methods:
/* Methods of L.Marker class */LMarker; // sets options of bouncing of all markersLMarker; // gets all bouncing markersLMarker; // asks all bouncing markers to stop /* Methods of marker instances */var marker = L;marker; // sets options of bouncing of this markermarker; // checks if marker is bouncingmarker; // starts the bouncingmarker; // makes marker bounce "n" timesmarker; // stops bouncing markermarker; // starts/stops bouncing of this 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 */var marker = L; /* Create a marker and define it's bouncing options. * Bouncing can be started/stoped by the click on the marker. */var marker = L ; /* Define options of bouncing for all markers */LMarker; /* Create 10 markers and each of them will bounce 3 times when clicked */for var i = 0; i < 10; i++ var marker = L ;
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 to 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 parameter. Animation can be customized with following properties:
- bounceHeight - how high marker will bounce (px), default: 15
- contractHeight - how much marker will contract when it touch 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 is disabled (radians), default: - Math.PI / 4 - elastic - activate contract animation when marker touch 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
Tested on
✅ Chrome 40.0
✅ Firefox 35.0
✅ IE 11
✅ Android 4.4/5.0
✅ Safari
License
Plugin distributed under BSD license.