javascript - Leaflet 的脉冲动画有奇怪的行为 [包括 GIF]

标签 javascript css leaflet

我想用 Leaflet 在标记上制作脉冲动画,但我遇到了一个非常奇怪的行为。

CSS

.mapbox-marker {
    mix-blend-mode: screen;
}

.animate {
    transition-property: transform;
    -webkit-animation: pulsate 30s ease-out;
    -webkit-animation-iteration-count: 1; 
    opacity: 0.0
}

@-webkit-keyframes pulsate {
0% {-webkit-transform: scale(0.1, 0.1); opacity: 0.0;}
50% {opacity: 1.0;}
100% {-webkit-transform: scale(1.2, 1.2); opacity: 0.0;}
}

这是我的标记

myCircleMarker = L.CircleMarker.extend({options: {
  radius: currentRadius,
  stroke: false,
  fillColor: '#FFFFFF',
  fillOpacity: 1,
  clickable: false,
  className: 'mapbox-marker animate'
}});

当我添加标记时

function addMarkersBatch(positions) {
    var markers = []
    positions.forEach(function(position) {
        var marker = new myCircleMarker(position);
        marker.setRadius(currentRadius*1.8);
        marker.setStyle({fillColor: "#fe5928"});
        map.addLayer(marker);
        markers.push(marker);
    });
}

动画符合预期,但带有非常奇怪的标记行为。我只希望标记在 map 位置上缩放,但它在缩放时在屏幕上移动。

The weird behaviour

希望大家帮忙

最佳答案

显然,修复非常简单。我只需要将 transform-origin 设置为居中

@-webkit-keyframes pulsate {
    0% {
        -webkit-transform: scale(0.0, 0.0); 
        opacity: 0.0;
        transform-origin:center;
    }
    1% {
        -webkit-transform: scale(1.5, 1.5); 
        opacity: 1.0;
    }
    5% {
        -webkit-transform: scale(0.8, 0.8); 
    }
    50% {
        opacity: 1.0;
    }
    100% {
        -webkit-transform: scale(0.4, 0.4); 
        opacity: 0.0;
    }
}

关于javascript - Leaflet 的脉冲动画有奇怪的行为 [包括 GIF],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38141081/

相关文章:

javascript - 使用特定变量从 PHP echo 调用 JS 函数时出现问题

css - 字体样式斜体有时在 Firefox 中不起作用

javascript - JQuery addClass 不适用于点击事件上的 anchor 标记

python - 在 Folium HeatMapWithTime 中显示日期、id 列和其他列

javascript - 传单未将平铺层添加到底部

javascript - jquery 无法更新背景颜色 css

javascript - 绘制多个彼此相邻的旋转图像

javascript - 如何用另一个 Div 替换一个 Div 但只替换一次

css - 滚动页面时导航栏不粘在顶部

javascript - 在美国 map 上保存所有 "features"的 Leaflet JS 对象在哪里?