签出这个Codepen(链接)或者它也可以作为一个要点(链接)
使用 SVG 笔触属性,我们为使用 rand 计算的不完美贝塞尔曲线生成的 SVG 线设置动画。我认为这应该非常接近您正在寻找的内容。
jQuery 和 D3 依赖项
<style>
path.ln {
stroke-width: 2px;
stroke: #999;
fill: none;
vector-effect: non-scaling-stroke;
stroke-dasharray: 1000;
stroke-dashoffset: 1000;
-webkit-animation: dash 4s cubic-bezier(0.45,0.3,0.35,0.3);
-moz-animation:dash 4s cubic-bezier(0.45,0.3,0.35,0.3);
-o-animation:dash 4s cubic-bezier(0.45,0.3,0.35,0.3);
animation:dash 4s cubic-bezier(0.45,0.3,0.35,0.3);
}
@keyframes dash {
to { stroke-dashoffset: 0; }
}
</style>
<script>
function path(min_rad_delta,max_rad_delta, el_min, el_max, el_min_delta,el_max_delta) {
var d = Math.sqrt( 0.5 * 0.5 + 1 * 1 ), r = 1; //returns the square root of a number
var el = (el_min + Math.random() * (el_max - el_min)) * Math.PI / 180;
var path = 'M' + [r * Math.sin(el), r * Math.cos(el)] + ' C' + [d * r * Math.sin(el + Math.LN2), d * r * Math.cos(el + Math.LOG10E)];
for (var i = 0; i < 4; i++) {
el += Math.PI / 2 * (1 + el_min_delta + Math.random() * (el_max_delta - el_min_delta));
r *= (1 + min_rad_delta + Math.random()*(max_rad_delta - min_rad_delta));
path += ' ' + (i?'S':'') + [d * r * Math.sin(el - 0.45), d * r * Math.cos(el - 0.45)];
path += ' ' + [r * Math.sin(el), r * Math.cos(el)];
}
return path;
}
function cX(lambda_min, lambda_max, el_min, el_max) {
var el = (el_min + Math.random()*(el_max - el_min));
return 'rotate(' + el + ') ' + 'scale(1, ' + (lambda_min + Math.random()*(lambda_max - lambda_min)) + ')'+ 'rotate(' + (-el) + ')';
}
</script>
<svg id="circle" width="50%" height="75%" viewBox='-1.5 -1.5 3 3'></svg>
<script>
d3.selectAll( 'svg' )
.append( 'path' )
.classed( 'ln', true)
.attr( 'd', path(-0.1,0, 0,360, 0,0.2 ))
.attr( 'transform', cX( 0.6, 0.8, 0, 360 ));
setTimeout(function() { location = '' } ,5000)
</script>