Skip to content

动画(animation)明明设置为了只执行一次,却会偶发的再次被触发 #1492

Answered by wumail
xingzilong asked this question in Q&A
Discussion options

You must be logged in to vote

这是两种不同的情况。在logicflow中,假如我们拖出两个不同类型的节点A和B,这时在DOM里AB同级,且顺序为AB,在点击A节点之后,A会被重新渲染,顺序变为BA,这是logicflow的渲染机制导致的,在代码中

https://github.com/didi/LogicFlow/blob/master/packages/core/src/view/Graph.tsx#L85
graphModel.sortElements是一个get方法,它会根据zIndex做排序,从而影响节点的渲染顺序

https://github.com/didi/LogicFlow/blob/master/packages/core/src/model/GraphModel.ts#L200
如果我们对节点的删除和添加做监听的话就可以发现,上面的操作会导致A节点(#html-node)的删除和添加

等同于

const dom = document.querySelector('#html-node')
const base = document.querySelector('.lf-base')
base.removeChild(dom)
base.appendChild(dom)

在这里,emerge动画是依照时间轴执行的,节点被「重新渲染」,时间轴重置了,动画自然也会重新执行

但是为节点添加class,并不会让对应的时间轴重置

以上是我的理解,可能有错误的地方,具体可以了解一下animation的机制以及完整的浏览器渲染机制,我也不太了解就不展开了。

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@xingzilong
Comment options

@wumail
Comment options

Answer selected by xingzilong
@xingzilong
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants