ZENLLC commited on
Commit
3637792
·
verified ·
1 Parent(s): 2bdf2b8

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +7 -14
script.js CHANGED
@@ -14,7 +14,6 @@
14
  };
15
  step();
16
  }
17
- // Run after mount
18
  setTimeout(initTicker, 100);
19
  })();
20
 
@@ -23,15 +22,11 @@
23
  let raf = null;
24
  let y = 0;
25
 
26
- function getScrollEl(){
27
- return document.getElementById("prompterScroll");
28
- }
29
- function getSpeedEl(){
30
- return document.getElementById("pSpeed");
31
- }
32
 
33
  function loop(){
34
- const el = getScrollEl();
35
  if(!el) return;
36
  const playing = (el.dataset.playing === "true");
37
  const speed = parseFloat(el.dataset.speed || "40"); // px/s
@@ -44,16 +39,16 @@
44
  }
45
 
46
  function togglePlay(){
47
- const el = getScrollEl(); if(!el) return;
48
  const playing = (el.dataset.playing === "true");
49
  el.dataset.playing = (!playing).toString();
50
  }
51
  function speedDelta(d){
52
- const el = getScrollEl(); if(!el) return;
53
  let s = parseFloat(el.dataset.speed || "40");
54
  s = Math.max(5, Math.min(200, s + d));
55
  el.dataset.speed = String(s);
56
- const sp = getSpeedEl(); if(sp) sp.textContent = `${Math.round(s)}px/s`;
57
  }
58
  function fullScreen(){
59
  const vp = document.querySelector(".prompter__viewport");
@@ -64,13 +59,11 @@
64
  document.exitFullscreen().catch(()=>{});
65
  }
66
  }
67
-
68
  function keyHandler(e){
69
  if(e.key === " "){ e.preventDefault(); togglePlay(); }
70
  if(e.key === "ArrowUp"){ e.preventDefault(); speedDelta(+5); }
71
  if(e.key === "ArrowDown"){ e.preventDefault(); speedDelta(-5); }
72
  }
73
-
74
  function clickBind(){
75
  const play = document.getElementById("pPlayPause");
76
  const slow = document.getElementById("pSlower");
@@ -85,6 +78,6 @@
85
 
86
  setTimeout(()=>{
87
  clickBind();
88
- if(!raf) loop();
89
  }, 120);
90
  })();
 
14
  };
15
  step();
16
  }
 
17
  setTimeout(initTicker, 100);
18
  })();
19
 
 
22
  let raf = null;
23
  let y = 0;
24
 
25
+ function elScroll(){ return document.getElementById("prompterScroll"); }
26
+ function elSpeed(){ return document.getElementById("pSpeed"); }
 
 
 
 
27
 
28
  function loop(){
29
+ const el = elScroll();
30
  if(!el) return;
31
  const playing = (el.dataset.playing === "true");
32
  const speed = parseFloat(el.dataset.speed || "40"); // px/s
 
39
  }
40
 
41
  function togglePlay(){
42
+ const el = elScroll(); if(!el) return;
43
  const playing = (el.dataset.playing === "true");
44
  el.dataset.playing = (!playing).toString();
45
  }
46
  function speedDelta(d){
47
+ const el = elScroll(); if(!el) return;
48
  let s = parseFloat(el.dataset.speed || "40");
49
  s = Math.max(5, Math.min(200, s + d));
50
  el.dataset.speed = String(s);
51
+ const sp = elSpeed(); if(sp) sp.textContent = `${Math.round(s)}px/s`;
52
  }
53
  function fullScreen(){
54
  const vp = document.querySelector(".prompter__viewport");
 
59
  document.exitFullscreen().catch(()=>{});
60
  }
61
  }
 
62
  function keyHandler(e){
63
  if(e.key === " "){ e.preventDefault(); togglePlay(); }
64
  if(e.key === "ArrowUp"){ e.preventDefault(); speedDelta(+5); }
65
  if(e.key === "ArrowDown"){ e.preventDefault(); speedDelta(-5); }
66
  }
 
67
  function clickBind(){
68
  const play = document.getElementById("pPlayPause");
69
  const slow = document.getElementById("pSlower");
 
78
 
79
  setTimeout(()=>{
80
  clickBind();
81
+ if(!raf) raf = requestAnimationFrame(loop);
82
  }, 120);
83
  })();