Recently I found awesome animation with shuffle list https://jsfiddle.net/chrisvfritz/sLrhk1bc/ I am amazed this. So I try do it same by using only CSS and jQuery.
I also tried to do it myself https://jsfiddle.net/stas0/68Lpwqgk/ But it no working as in vue shuffle.
As I read before I am understand that element must move in DOM tree but I don't know how add animation to it. I gues that I need use transform but can't understand how maybe use transform: translate
but in vue example I didn't find translate options.
So my target is create simple shuffle(in my link example only two items) like in Vue only with CSS and jQuery.
Thanks.
The reason why you don't see any translate
s (or matrix
s, for that matter) transforms on the initial example is because the transformations are performed in the <transition-group>
directive.
Without this directive, the change would be instant. The elements would jump to their new positions. What <transition-group>
does is:
In order to allow control over the animation, <transition-group>
applies transition classes to each transitioning element.
In the original example,
.cell-move {
transition: transform 1s;
}
controls the animation, because:
name
of the transform-group
is cell
. move
(the transformed children move their position in the parent).To better visualize what's going on, watch their indexes .
So, in order to replicate the same effect, you need to:
getBoundingClientRect
on each) and use them to transition the original elements to the cloned ones positionsImportant note: you don't have to actually insert the clone in DOM in order to calculate the new positions, but doing so makes things easier, especially if you don't understand everything happening behind the scenes.
The important part is that the clone does not trigger a redraw in the Layout and Paint layers of your document. It basically has to have position:absolute
throughout its entire life-cycle.
Even though your question has a different flavor (ie: "How does Vue do it?" ), technically, your question has been asked and answered before. For example, a quick search through my answers with clone
and/or transition
will likely pop similar answers. Here's a similar one .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.