mxGraph添加流动的管道动画

效果图:
在这里插入图片描述

1、使用css3定义流动的class

/**
* 管道动画
* 线段长度为8,每0.5s执行一次keyframes中定义的dash动作,且无限循环执行
*/
.flowStyle {
  stroke-dasharray: 8;
  animation: dash 0.5s linear;
  animation-iteration-count: infinite;
}
@keyframes dash {
  to {
    stroke-dashoffset: -16;
  }
}

2、给管道添加流动动画

addAnimation (cells) {
  // 取出需要添加动画的管道线,这里随机取的第二个管道 - 可自定义
  const cell = cells.filter(item => item.edge)[1]; 
  const state = this.graph.view.getState(cell);
  
  // 设置管道可见,宽度为6,且为亮灰色
  state.shape.node.getElementsByTagName("path")[0].removeAttribute("visibility");
  state.shape.node.getElementsByTagName("path")[0].setAttribute("stroke-width", "6");
  state.shape.node.getElementsByTagName("path")[0].setAttribute("stroke", "lightGray");
  
  // 设置流动线段宽度为3,红色,并添加流动动画
  state.shape.node.getElementsByTagName("path")[1].setAttribute("stroke-width", "3");
  state.shape.node.getElementsByTagName("path")[1].setAttribute("stroke", "red");
  state.shape.node.getElementsByTagName("path")[1].setAttribute("class", "flowStyle");
  
  // 设置箭头为红色
  state.shape.node.getElementsByTagName("path")[2].setAttribute("stroke", "red");
  state.shape.node.getElementsByTagName("path")[2].setAttribute("fill", "red");   
},
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值