Skip to content

Commit

Permalink
fix: use requestAnimationFrame on volume slider drag to prevent jitter
Browse files Browse the repository at this point in the history
  • Loading branch information
jkeen committed Mar 21, 2024
1 parent 4c5c692 commit 98fd36b
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions ember-stereo/src/modifiers/stereo-volume.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ export default class StereoVolumeModifier extends Modifier {

@action
handleTap(e) {
e.preventDefault();
var rect = this.element.getBoundingClientRect();
// Check if the event is a touch event
let x;
if (e.type === 'touchmove') {
x = e.touches[0].clientX - rect.left; // x position within the element for touch event
} else {
x = e.clientX - rect.left; // x position within the element for mouse click
}
let volumeLevel = parseInt((x / rect.width) * 100, 10);
this.setVolume(volumeLevel)
window.requestAnimationFrame(() => {
e.preventDefault();
var rect = this.element.getBoundingClientRect();
// Check if the event is a touch event
let x;
if (e.type === 'touchmove') {
x = e.touches[0].clientX - rect.left; // x position within the element for touch event
} else {
x = e.clientX - rect.left; // x position within the element for mouse click
}
let volumeLevel = parseInt((x / rect.width) * 100, 10);
this.setVolume(volumeLevel)
})
}

@action
Expand Down

0 comments on commit 98fd36b

Please sign in to comment.