A "Wheel of Fortune" component just popped up in my feed. I always spin, but never win! Anyway, this type of component is often built with <canv...
For further actions, you may consider blocking this person and/or reporting abuse
The height calculation is actually not correct. You need to consider the polygon shape around the circle to find the correct height (the circumscribed polygon)
It's equal to
height: calc(2*50cqi*tan(180deg/var(--_items)));
that you can simplify by setting the ratioaspect-ratio: 1/calc(2*tan(180deg/var(--_items)));
to avoid using the width value twice.With this you won't have issue when you apply the clip-path
AH, perfect — thank you! You truly are the master of CSS Shapes. I've added an update, and will use your input for the follow-up article with spinning.
Thank you for this amazing article! Everything works flawlessly, as long as it's more than 3 items. For anything less than three, I get some very weird behaviors (these are 1 item, 2 items, and 3 items):
I am trying to find a fix for these, although I suspect it will have to be in js instead of css. I will come back and let you know my solution.
Weird — let me know your findings, otherwise I can look into it in the weekend.
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!
I really like your implementation because all libs create a wheel using canvas but i need the one to be highly customizable. Please help me to add logic to spin the wheel to the predefined (from backend or mocked) sector!
You just need to set
newEndDegree
manually, matching your predefined destination.Has anyone solved the return value of the winning field? For example index for li tag. I have something, but the results are +- one position.
I think it’s resolved ( Link on Codepen.io ).
Cool!
Please share — I need to think about it too!
Always here for an interesting CSS project. Kudos.
Thanks!
wholesome wheel! :)
Beautiful project!
Thank you!
I suppose this would be easier done in pure Javasript using CSS only where It's appropriate (e.g. the animation). Is it really worth the effort doing anything in CSS?
I don't think that'd be easier in javascript. Whenever you have something visual, the right tool for that is CSS. When it's easier in pure JS, this usually mean that you lack knowledge with CSS.
Oh, have fun to rebuild the [solarsystem][dev.to/cookiemonsterdev/solar-syst...] with pure CSS. There are good reasons the S in
CSS comes from "style", not from graphics...
So I found this posting a few days ago. I used the code pen and am trying to make this into a dynamically loading setup. Everything is fine with the wedges until you get below 4 slices. At 3 and less it breaks. I feel like it's something to do with the aspect ration of the LI tags.
Any thoughts?
I have a solution here: dev.to/skamansam/comment/2l9ni