Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. // 監聽事件
  2. let mousedown = false;
  3. progress.addEventListener("click", scrub);
  4. // progress.addEventListener("mousemove", (e) => {
  5. // if (mousedown) {
  6. // scrub(e);
  7. // }
  8. // });
  9.  
  10. // if mousedown is true, moves on running scrub(), if mousedown is false, it's not going to run the scrub
  11. progress.addEventListener("mousemove", (e) => mousedown && scrub(e));
  12. progress.addEventListener("mousedown", () => mousedown = true);
  13. progress.addEventListener("mouseup", () => mousedown = false);
  14.  
  15.  
  16. function scrub(e) {
  17. // console.log(e);
  18. const scrubTime = (e.offsetX / progress.offsetWidth) * video.duration;
  19. video.currentTime = scrubTime;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement