Skip to content

Commit 4157e98

Browse files
committed
Use hardware-accelerated translate3d.
1 parent bec5af8 commit 4157e98

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

src/utils/getDetachedContainerStyles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ export default function getDetachedContainerStyles(openDirection, anchorDirectio
3434
}
3535

3636
return {
37-
transform: `translateX(${offsetX}px) translateY(${offsetY}px)`,
37+
transform: `translate3d(${offsetX}px, ${offsetY}px, 0)`,
3838
};
3939
}

test/utils/getDetachedContainerStyles_spec.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,23 @@ describeIfNoWindow('#getDetachedContainerStyles', () => {
3232
describe('on down-left positioning', () => {
3333
it('returns translation from top-left of window to top-left of reference el', () => {
3434
const styles = getDetachedContainerStyles(OPEN_DOWN, ANCHOR_LEFT, referenceEl);
35-
expect(styles.transform).to.have.string(`translateX(${referenceElRect.left}px)`);
36-
expect(styles.transform).to.have.string(`translateY(${referenceElRect.top}px)`);
35+
expect(styles.transform).to.equal(`translate3d(${referenceElRect.left}px, ${referenceElRect.top}px, 0)`);
3736
});
3837
});
3938

4039
describe('on up-left positioning', () => {
4140
it('returns translation from bottom-left of window to bottom-left of reference el', () => {
4241
const styles = getDetachedContainerStyles(OPEN_UP, ANCHOR_LEFT, referenceEl);
4342
const offsetY = -(windowHeight - referenceElRect.bottom);
44-
expect(styles.transform).to.have.string(`translateX(${referenceElRect.left}px)`);
45-
expect(styles.transform).to.have.string(`translateY(${offsetY}px)`);
43+
expect(styles.transform).to.equal(`translate3d(${referenceElRect.left}px, ${offsetY}px, 0)`);
4644
});
4745
});
4846

4947
describe('on down-right positioning', () => {
5048
it('returns translation from top-right of window to top-right of reference el', () => {
5149
const styles = getDetachedContainerStyles(OPEN_DOWN, ANCHOR_RIGHT, referenceEl);
5250
const offsetX = -(windowWidth - referenceElRect.right);
53-
expect(styles.transform).to.have.string(`translateX(${offsetX}px)`);
54-
expect(styles.transform).to.have.string(`translateY(${referenceElRect.top}px)`);
51+
expect(styles.transform).to.equal(`translate3d(${offsetX}px, ${referenceElRect.top}px, 0)`);
5552
});
5653
});
5754

@@ -60,8 +57,7 @@ describeIfNoWindow('#getDetachedContainerStyles', () => {
6057
const styles = getDetachedContainerStyles(OPEN_UP, ANCHOR_RIGHT, referenceEl);
6158
const offsetX = -(windowWidth - referenceElRect.right);
6259
const offsetY = -(windowHeight - referenceElRect.bottom);
63-
expect(styles.transform).to.have.string(`translateX(${offsetX}px)`);
64-
expect(styles.transform).to.have.string(`translateY(${offsetY}px)`);
60+
expect(styles.transform).to.equal(`translate3d(${offsetX}px, ${offsetY}px, 0)`);
6561
});
6662
});
6763
});

0 commit comments

Comments
 (0)