Leaflet.js circleMarker过渡

时间:2018-10-23 08:21:40

标签: leaflet

有人知道我如何用circleMarker在leaflet.js中进行转换吗? 在较旧的版本(如果我没记错的话,为0.7)中,以下css可以实现技巧

.leaflet-clickable {
        transition: all .3s;
    }

,但现在不再。我正在使用version 1.3.1

1 个答案:

答案 0 :(得分:2)

设置custom class on your marker并使用它来设置过渡。例如:

使用此标记

L.circleMarker([0, 0], {
    className: 'circle-transition'
}).addTo(map)

您可以通过以下方式进行悬停过渡

.circle-transition:hover {
    fill: red;
    fill-opacity: 1;
    transition: all 1s
}

还有一个演示

var map = L.map('map').setView([0, 0], 4);

L.circleMarker([0, 0], {
    radius: 100, 
    className: 'circle-transition',
    fillOpacity: 0.5
}).addTo(map)
html, body {
    height: 100%;
    margin: 0;
}
#map {
    width: 100%;
    height: 100%;
}


@keyframes fadeIn { 
  from { fill-opacity:0; } 
  to { fill-opacity:0.5; } 
}
.circle-transition {
   animation: 1s ease-out 0s 1 fadeIn;
}
.circle-transition:hover {
    fill: red;
    fill-opacity: 1;
    transition: all 1s
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.4/leaflet.css"/>

<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.4/leaflet.js"></script>

<div id='map'></div>