当用户将鼠标悬停在
:如何修改代码,以便当用户执行不同的事件(例如加载 html)时,它会启动画线的函数。谢谢!
$(function() {
animateLine = function(canvas, hoverDivName, colorNumber, pathString) {
$('#' + hoverDivName).hover(
function() {
var line = canvas.path(pathString).attr({
stroke: colorNumber
});
var length = line.getTotalLength();
$('path[fill*="none"]').animate({
'to': 1
}, {
duration: 5000,
step: function(pos, fx) {
var offset = length * fx.pos;
var subpath = line.getSubpath(0, offset);
canvas.clear();
canvas.path(subpath).attr({
stroke: colorNumber,
"stroke-dasharray":"--",
"stroke":"#a36d66"
});
},
});
}, function() {
$('path[fill*="none"]').stop(true, false);
});
};
var canvas = Raphael('canvas', 900, 648);
var pathString = "m441.5,223.5c67,-85 47,246 180,110c12,-43 24,-81 8, T1600 ";
animateLine(canvas, "canvas", "#000", pathString);
});
<div id="canvas">
<p>Hover over me</p>
</div>