Skip to content

Commit 934ce7c

Browse files
committed
update function with requestAnimationFrame
1 parent 3515ff7 commit 934ce7c

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

side-nav/side-nav.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class SideNav {
3131
this.onTouchMove = this.onTouchMove.bind(this);
3232
this.onTouchEnd = this.onTouchEnd.bind(this);
3333
this.onTransitionEnd = this.onTransitionEnd.bind(this);
34+
this.update = this.update.bind(this);
3435

3536
this.startX = 0;
3637
this.currentX = 0;
@@ -55,6 +56,8 @@ class SideNav {
5556

5657
this.startX = evt.touches[0].pageX;
5758
this.currentX = this.startX;
59+
60+
requestAnimationFrame(this.update);
5861
}
5962

6063
onTouchMove (evt) {
@@ -64,8 +67,6 @@ class SideNav {
6467
if (translateX < 0) {
6568
evt.preventDefault();
6669
}
67-
68-
this.sideNavContainerEl.style.transform = `translateX(${translateX}px)`;
6970
}
7071

7172
onTouchEnd (evt) {
@@ -77,6 +78,16 @@ class SideNav {
7778
}
7879
}
7980

81+
update () {
82+
if (!this.sideNavEl.classList.contains('side-nav--visible'))
83+
return;
84+
85+
requestAnimationFrame(this.update);
86+
87+
const translateX = Math.min(0, this.currentX - this.startX);
88+
this.sideNavContainerEl.style.transform = `translateX(${translateX}px)`;
89+
}
90+
8091
blockClicks (evt) {
8192
evt.stopPropagation();
8293
}

0 commit comments

Comments
 (0)