jsplumb库笔记

1. 初始化

jsPlumb 提供 getInstance 方法来创建一个新的实例。可以在实例化时配置一些全局选项。

jsPlumb.ready(function() {
    var instance = jsPlumb.getInstance({
        PaintStyle: {//连接线样式
            stroke: "#5c96bc",
            strokeWidth: 2
        },
        HoverPaintStyle: {//连接线选中样式
            stroke: "#1e8151",
            strokeWidth: 2
        },
        EndpointStyle: {//端点样式
            width: 10,
            height: 10,
            stroke: "#7AB02C"
        },
        Endpoint: "Dot",//端点类型
        Anchors: ["TopCenter", "BottomCenter"]
    });
});

2. 创建连接

可以通过 connect 方法创建连接。

instance.connect({
    source: "element1",//开始元素
    target: "element2",//结束元素
    connector: ["Bezier", { curviness: 50 }],//连接线的配置
    paintStyle: { stroke: "#5c96bc", strokeWidth: 2 },
    hoverPaintStyle: { stroke: "#1e8151", strokeWidth: 2 },
    overlays: [//覆盖物
        ["Arrow", { width: 10, length: 10, location: 1 }],//箭头
        ["Label", { label: "Label text", id: "label", cssClass: "labelClass" }]
    ]
});

实战

需求要流动的箭头动画效果

overlays: [["Arrow", { width: 10, length: 10, location: this.m }]]
/*
location是遮盖物在线上我位置的占比最大为1

所以不断修改location的值就能达到流动的动画效果
*/

         const animate = () => {
            this.m += 0.004;
            if (this.m > 0.98) {
              this.m = 0.012;
            }
            this.instance.deleteEveryConnection();

            const common = {
              connector: "StateMachine",
              cssClass: "animated-flow",
              endpoint: "Blank",
              anchor: ["Left", "Right"],
              overlays: [["Arrow", { width: 10, length: 10, location: this.m }]],
            };


              this.instance.connect({ source: common.source, target: common.target }, {
                ...common
              });

            this.animationFrameId = requestAnimationFrame(animate);
         }
         this.animationFrameId = requestAnimationFrame(animate);

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值