js+css动画实现动态流⽔线条效果需求让实现每个模块之间的线动态流⽔化,⽤canvas肯定很复杂,所有⽤了⽐较投机的⽅法,css动画加js控制
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
<style type="text/css">
*{
padding:0;margin:0;
}
.container{
background:black;
position:relative;border:1px solid #ddd;
width:1000px;height:800px;
}
.sparkLine{
position: absolute;transform-origin:left top;
}
.sparkLine .sparkParticle{
canvas动画width:1px;height:1px;float:left;
color:white;background: white;
box-shadow: 0 0 10px white;
opacity: 0;
}
@keyframes fade {
0% {
opacity: 0;
}
50% {
opacity: 1;
}
100% {
opacity: 0;
}
}
.sparkLine .sparkParticle {
}
</style>
</head>
<body>
<div class="container">
<div class="sparkLine" >
<div class="sparkParticle"></div>
</div>
</div>
<script type="text/javascript">
function createLine(num,color,width,height,speed,left,top,deg){
/
/粒⼦数(px),颜⾊,宽度,⾼度,速度,位置左,位置右,⾓度
var $sparkLine=$('<div class="sparkLine"></div>');
$sparkLine.css("top",top);
$sparkLine.css("left",left);
$sparkLine.css("height",height);
$sparkLine.css("transform",' rotateZ('+deg+'deg)');
for(var i=0;i<num;i++){
var $sparkParticle=$('<div class="sparkParticle"></div>');
$sparkParticle.css("-webkit-animation","fade "+speed+"s "+i/100+"s infinite");
$sparkParticle.css("width",width);
$sparkParticle.css("height",height);
$sparkParticle.css("background",color);
$sparkLine.append($sparkParticle)
}
$(".container").append($sparkLine)
}
//创建线
createLine(200,'red',2,2,1,20,20,30);
createLine(200,'white',2,2,1,20,20,90);
</script>
</body>
</html>
这只是个测试例⼦,⽤到了jq,例⼦中只有两条线,根据⾃⼰实际情况调⽤createLine⽅法创建线条并传⼊各种参数

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。