Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit 5fa1141

Browse files
crabmusketyyx990803
authored andcommitted
Fix performance issue in applyMoveTransition (#6)
getBoundingClientRect causes a DOM reflow when the DOM has been written to between calls (see http://stackoverflow.com/a/37686736/945863). So call gBCR on each element first in one loop with no intermediate writes, then use those results while writing to the DOM in a second loop.
1 parent b709a9a commit 5fa1141

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

vue-animated-list.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@
7373
*/
7474

7575
function applyMoveTransition (frags) {
76+
frags.forEach(function (frag) {
77+
frag._newPos = frag.node.getBoundingClientRect()
78+
})
7679
frags.forEach(function (frag) {
7780
var node = frag.node
7881
var oldPos = frag._oldPos
@@ -87,9 +90,8 @@
8790
p.removeChild(node)
8891
p.insertBefore(node, next)
8992
}
90-
var newPos = node.getBoundingClientRect()
91-
var dx = oldPos.left - newPos.left
92-
var dy = oldPos.top - newPos.top
93+
var dx = oldPos.left - frag._newPos.left
94+
var dy = oldPos.top - frag._newPos.top
9395
if (dx !== 0 || dy !== 0) {
9496
frag.moved = true
9597
node.style.transform =

0 commit comments

Comments
 (0)