使用 RaphaelJS,我改编了几个脚本来创建两个我想要组合的动画:
首先,绘制虚线坐标http://jsfiddle.net/jbirthler/CvhKx/2/
var canvas = Raphael('canvas_container', 322, 273); var set = canvas.set(canvas.circle(110, 265, 7), canvas.circle(110, 7, 7), canvas.circle(7, 151, 7)).attr({ stroke: "none", fill: "#666" }); var pathstr = "M 109 255 l 0 -245 l -103 141 l 265 0"; var path = dashline(canvas, pathstr, 4000, { stroke: '#828282', 'stroke-dasharray': "--", 'stroke-linecap': "butt", 'stroke-width': 1, 'fill-opacity': 0 }, 1000); function dashline(canvas, pathstr, duration, attr) { var guide_path = canvas.path(pathstr).attr({ stroke: "none", fill: "none" }); var path = canvas.path(guide_path.getSubpath(0, 1)).attr(attr); var total_length = guide_path.getTotalLength(guide_path); var start_time = new Date().getTime(); var interval_length = 20; var interval_id = setInterval(function() { var elapsed_time = new Date().getTime() - start_time; var this_length = elapsed_time / duration * total_length; var subpathstr = guide_path.getSubpath(0, this_length); attr.path = subpathstr; path.animate(attr, interval_length); }, interval_length); return path; };
并且,在到达坐标http://jsfiddle.net/jbirthler/KqjHh/1/时,在路径上缓和动画圈
var canvas = Raphael("holder", 322, 273); var set = canvas.set(canvas.circle(110, 265, 7),canvas.circle(110, 7, 7), canvas.circle(7, 151, 7)).attr({stroke:"none", fill: "#666"}); var c = canvas.circle(110, 265, 10).attr({stroke: "#ddd", "stroke-width": 4}); var fade = function (id) { return function () { set[id].attr({fill: "#fff", r: 12}).animate({fill: "#77bf00", r: 8}, 500); }; }; var run = animateCirc(); function animateCirc() { var easex = ">", easey = ">"; c.stop().animate({ "0%": {cy: 265, easing: easey, callback: fade(0)}, "40%": {cy: 7, easing: easey, callback: fade(1)}, "60%": {cy: 151, easing: easey, callback: fade(2)}, "100%": {cy: 151, easing: easey, callback: fade(3)} }, 3000).animate({ "0%": {cx: 110, easing: easex}, "40%": {cx: 110, easing: easex}, "60%": {cx: 7, easing: easex}, "100%": {cx: 300, easing: easex} }, 3000); return run; };
当虚线路径到达它们的坐标时,我想让圆圈动画。如果我能获得使用缓动的虚线路径,那将是一个加号,但大多数情况下,我只是希望将两者合二为一。
我能够比编写自己的脚本更好地阅读 javascript,但是如果有人对如何分解虚线脚本和代码所采取的步骤有任何见解,那对我来说将是非常有益的。
我关于堆栈溢出的第一篇文章(是的,是时候了)希望我足够具体!