|
156 | 156 | window.setTimeout(function () { play(); schedule(); }, 800 + idx * 850); |
157 | 157 | }); |
158 | 158 |
|
159 | | - // One trigger mechanism only: hover on devices that have it, touch on those |
160 | | - // that don't. We never bind "click", so a tap doesn't double-fire and a |
161 | | - // mouse click on desktop stays inert. |
162 | | - var canHover = window.matchMedia("(hover: hover)").matches; |
| 159 | + // One trigger per input type, discriminated by pointerType rather than a |
| 160 | + // (hover: hover) media query — devices with a hovering stylus (e.g. the |
| 161 | + // Galaxy S24 Ultra's S Pen) report hover:hover even though the user taps |
| 162 | + // with a finger, which would otherwise trap touch in the hover path (plays |
| 163 | + // once, then needs a mouseleave elsewhere before it can replay). |
| 164 | + // - mouse / pen hover: replay on enter, restore the loop on leave. |
| 165 | + // - finger touch: replay on every tap, then restart the loop clock. |
| 166 | + // We never bind "click", so a tap doesn't double-fire and a desktop click |
| 167 | + // stays inert. |
163 | 168 | Array.prototype.forEach.call(document.querySelectorAll("h2"), function (h2) { |
164 | 169 | var gx = h2.querySelector(".gx"); |
165 | 170 | if (!gx) return; |
166 | | - if (canHover) { |
167 | | - h2.addEventListener("mouseenter", function () { gx._pause(); gx._play(); }); |
168 | | - h2.addEventListener("mouseleave", function () { gx._pause(); gx._resume(); }); |
169 | | - } else { |
170 | | - // Touch screens: replay once on tap, then restart the auto-loop clock. |
171 | | - h2.addEventListener("touchstart", function () { |
172 | | - gx._pause(); gx._play(); gx._resume(); |
173 | | - }, { passive: true }); |
174 | | - } |
| 171 | + h2.addEventListener("pointerenter", function (e) { |
| 172 | + if (e.pointerType === "touch") return; // touch handled below |
| 173 | + gx._pause(); gx._play(); |
| 174 | + }); |
| 175 | + h2.addEventListener("pointerleave", function (e) { |
| 176 | + if (e.pointerType === "touch") return; |
| 177 | + gx._pause(); gx._resume(); |
| 178 | + }); |
| 179 | + h2.addEventListener("touchstart", function () { |
| 180 | + gx._pause(); gx._play(); gx._resume(); |
| 181 | + }, { passive: true }); |
175 | 182 | }); |
176 | 183 | } |
177 | 184 |
|
|
0 commit comments