I found a solution, but it's not mathematical in nature, it's kinda brute-force, especially the clip-path on the 3-item spinner. I tried all sorts of math for the clip-paths, but none of it worked close to well, and if you think about the problem, there really isn't a need for complex maths for one or two items.
NOTE: I added a data-itemCount property on the UL element to make this easier.
As another "optimization," I switched out the correct answer logic because it wasn't working well for me when the spinner landed on or near boundaries. I calculate it like a spinner would - by position.
NOTE: my spinner element has a header for a title, so I use the header to find the correct value at the position.
constspinnerElement=document.querySelector('.spinner-with-header');constheaderElement=spinnerElement.querySelector('.header');functiongetResultsAtTop(){if (!spinnerElement)returnnull;constrect=headerElement.getBoundingClientRect();constcenterX=rect.left+rect.width/2;consttopY=rect.top+rect.height+30;// 30 pixels below the headerconstelement=document.elementFromPoint(centerX,topY);if (element?.parentElement!==spinnerElement)returnnull;returnelement?.textContent?.trim()||null;}
I found a solution, but it's not mathematical in nature, it's kinda brute-force, especially the
clip-path
on the 3-item spinner. I tried all sorts of math for the clip-paths, but none of it worked close to well, and if you think about the problem, there really isn't a need for complex maths for one or two items.As another "optimization," I switched out the correct answer logic because it wasn't working well for me when the spinner landed on or near boundaries. I calculate it like a spinner would - by position.
I have a full customizable svelte componenent at github.com/skamansam/ultimate-spin.... The companion site is at rudeboy.dev/ultimate-spinner/
Here is the codepen forked from the one above, with my modifications in it -
Great, looks good!