【发布时间】:2015-02-12 23:37:26
【问题描述】:
我有一个 SVG 路径,我正在尝试使用 jquery.appear 插件对其进行动画处理。
这就是它的样子:
<svg class="animated" width="1170" height="350">
<path d="M60 112,L151 237,L266 113"
style="stroke: #2c3e50;
fill:none;
stroke-width:3px;
stroke-linejoin: miter;
stroke-miterlimit: 20.0;" />
</svg>
和 JS:
function simulatePathDrawing(path) {
var length = path.getTotalLength();
path.style.transition = path.style.WebkitTransition = 'none';
path.style.strokeDasharray = length + ' ' + length;
path.style.strokeDashoffset = length;
path.getBoundingClientRect();
path.style.transition = path.style.WebkitTransition = 'stroke-dashoffset 2.5s ease-in-out';
path.style.strokeDashoffset = '0';
path.style.strokeWidth = '3px';
};
$('.animated path').appear(function() {
simulatePathDrawing(this);
});
但是,如果我尝试使用鼠标悬停功能运行它,它会起作用。有什么建议吗?
var chars = $('.animated path').on('mouseover', function(e) {
simulatePathDrawing(this)
});
【问题讨论】:
标签: jquery function svg path jquery-animate