简体   繁体   中英

Animated transition of leaflet Marker icon

I have a Leaflet marker with a BLUE icon (from a PNG image source). On mouse hovering, I want to make that a RED icon.

This is the code for doing so:

            let placeMarker = L.marker(...);

            let cssSetter = function (imarker, iicon) {
                imarker.setIcon(iicon);
            };

            placeMarker.on('mouseover', 
                L.bind(cssSetter, null, placeMarker, markerIcon_red)
            );
            placeMarker.on('mouseout', 
                L.bind(cssSetter, null, placeMarker, markerIcon)
            );

Now I want to do this transition gradually, with an animation.

How can I do this?

Write your own CSS transition.

http://css3.bradshawenterprises.com/cfimg/


Or use plugin Leaflet.TransitionedIcon

https://github.com/naturalatlas/leaflet-transitionedicon

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM