Created
October 22, 2018 18:38
-
-
Save Stamo-Gochev/1497695b5dc97af3b89aea7f442dc45b to your computer and use it in GitHub Desktop.
Wheel of fortune - stolen from https://codepen.io/jkantner/pen/ReJPOV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.addEventListener("DOMContentLoaded",wof); | |
function wof() { | |
var arrow = document.querySelector(".arrow"), | |
arrowAngle = 0, | |
wheelAngle = 0, | |
snapAngle = 360/24/3, | |
getAngle = function(ele) { | |
let el = document.querySelector(ele), | |
elTr = el.style.transform, | |
// break down matrix value of transform and get angle | |
matrixVal = elTr.split('(')[1].split(')')[0].split(','), | |
cos1 = matrixVal[0], | |
sin = matrixVal[1], | |
angle = Math.round(Math.atan2(sin, cos1) * (180 / Math.PI)); | |
// convert negative angles to positive, correct -0 issue | |
if (angle < 0) { | |
angle += 360; | |
if (angle == "-0") { | |
angle = 0; | |
} | |
} | |
return angle; | |
}, | |
updateArrowAngle = function() { | |
let newWheelAngle = getAngle(".wheel"); | |
if (newWheelAngle > wheelAngle) { | |
// right | |
arrowAngle = snapAngle - (newWheelAngle % snapAngle) * 16; | |
} else if (newWheelAngle < wheelAngle) { | |
// left | |
arrowAngle = snapAngle - (newWheelAngle % snapAngle) * 16 + 64; | |
} | |
arrow.style.transform = "rotate(" + arrowAngle + "deg)"; | |
wheelAngle = newWheelAngle; | |
}; | |
Draggable.create(".wheel", { | |
type: "rotation", | |
throwProps: true, | |
dragResistance: 0, | |
minDuration: 3, | |
snap: function(endValue) { | |
return Math.round(endValue / snapAngle) * snapAngle; | |
}, | |
onDrag: updateArrowAngle, | |
onThrowComplete: function() { | |
arrowAngle = 0; | |
updateArrowAngle(); | |
}, | |
onThrowUpdate: updateArrowAngle | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*, *:before, *:after { | |
border: 0; | |
box-sizing: border-box; | |
margin: 0; | |
padding: 0; | |
} | |
:root { | |
font-size: 10px; | |
} | |
body { | |
background: rgb(0,128,192); | |
font: 1em Georgia; | |
font-weight: bold; | |
line-height: 1.5; | |
overflow-x: hidden; | |
} | |
main, .arrow, .wheel { | |
margin: auto; | |
} | |
main { | |
display: block; | |
margin-top: 3em; | |
width: 48em; | |
} | |
.arrow, .wheel { | |
position: relative; | |
} | |
.arrow { | |
background: rgb(255,255,255); | |
border-radius: 50% 50% 50% 50% / 25% 25% 75% 75%; | |
width: 1em; | |
height: 3em; | |
transition: transform 0.1s linear; | |
transform-origin: 0.5em 0.5em; | |
z-index: 1; | |
} | |
.wheel { | |
$st: 100%/24; | |
background: | |
radial-gradient(rgba(200,171,55,0) 22.9rem,rgb(200,171,55) 23rem), | |
radial-gradient(rgb(55,200,55) 7.9rem,rgba(55,200,55,0) 8rem), | |
conic-gradient( | |
rgba(32,255,0,0) $st*0.5, | |
rgb(32,255,0) 0 $st*1.5, | |
rgb(252,255,3) 0 $st*2.5, | |
rgb(255,0,0) 0 $st*3.5, | |
rgb(53,192,255) 0 $st*4.5, | |
rgb(251,192,0) 0 $st*5.5, | |
rgb(192,128,255) 0 $st*6.5, | |
rgb(252,255,3) 0 $st*7.5, | |
rgb(253,127,224) 0 $st*8.5, | |
rgb(250,32,0) 0 $st*9.5, | |
rgb(53,192,255) 0 $st*10.5, | |
rgb(32,255,0) 0 $st*11.5, | |
rgb(253,127,224) 0 $st*12.5, | |
rgb(0,0,0) 0 $st*13.5, | |
rgb(192,128,255) 0 $st*14.5, | |
rgb(252,255,3) 0 $st*15.5, | |
rgb(53,192,255) 0 $st*16.5, | |
rgb(255,255,255) 0 $st*17.5, | |
rgb(250,32,0) 0 $st*18.5, | |
rgb(192,128,255) 0 $st*19.5, | |
rgb(253,127,224) 0 $st*20.5, | |
rgb(34,255,0) 0 $st*21.5, | |
rgb(251,192,0) 0 $st*22.5, | |
rgb(192,128,255) 0 $st*23.5, | |
rgba(192,128,255,0) 0 $st*24 | |
), | |
repeating-linear-gradient(53deg,rgb(224,224,224),rgb(224,224,224) 0.1em,rgb(208,208,208) 0.1em,rgb(208,208,208) 0.2em); | |
border-radius: 50%; | |
box-shadow: 0 0 0.5em 0.25em rgba(0,0,0,0.4); | |
font-size: 3.75em; | |
margin-top: -1.5rem; | |
position: relative; | |
width: 48rem; | |
height: 48rem; | |
} | |
.sector { | |
display: flex; | |
position: absolute; | |
top: 0; | |
left: 50%; | |
line-height: 0.8; | |
text-align: center; | |
text-transform: uppercase; | |
width: 7rem; | |
height: 24rem; | |
transform-origin: 50% 100%; | |
user-select: none; | |
-moz-user-select: none; | |
-webkit-user-select: none; | |
-ms-user-select: none; | |
&:before, &:after, span { | |
display: block; | |
} | |
&:before, &:after { | |
background: rgba(255,255,255,0.5); | |
border-radius: 50%; | |
content: ""; | |
position: absolute; | |
bottom: 0; | |
left: 50%; | |
width: 1rem; | |
height: 1rem; | |
} | |
&:before { | |
transform: translateX(-50%) rotate(-360deg/48) translateY(24rem); | |
} | |
&:after { | |
box-shadow: -2rem 0 0 rgba(255,255,255,0.5); | |
transform: translateX(-50%) rotate(-360deg/144) translateY(24rem) rotate(2.5deg); | |
} | |
> span { | |
margin: auto; | |
transform: translateY(-4rem); | |
width: 3.5rem; | |
} | |
@for $s from 1 through 24 { | |
&:nth-of-type(#{$s}) { | |
@if $s == 14 { | |
perspective: 6rem; | |
> span { | |
color: rgb(255,255,255); | |
transform: translateY(-2rem) scaleY(0.5) rotateX(-6deg); | |
width: 5rem; | |
} | |
} | |
@elseif $s == 18 { | |
perspective: 8rem; | |
> span { | |
transform: translateY(-2rem) scale(0.8,0.6) rotateX(-20deg); | |
width: 5rem; | |
> span { | |
font-size: 1.4rem; | |
line-height: 1; | |
} | |
} | |
} | |
transform: translateX(-50%) rotate(360deg/24 * ($s - 1)); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<main> | |
<div class="arrow"></div> | |
<div class="wheel"> | |
<div class="sector"><span><small>$</small><br>5<br>0<br>0<br>0</span></div> | |
<div class="sector"><span><small>$</small><br>6<br>0<br>0</span></div> | |
<div class="sector"><span><small>$</small><br>5<br>0<br>0</span></div> | |
<div class="sector"><span><small>$</small><br>3<br>0<br>0</span></div> | |
<div class="sector"><span><small>$</small><br>5<br>0<br>0</span></div> | |
<div class="sector"><span><small>$</small><br>8<br>0<br>0</span></div> | |
<div class="sector"><span><small>$</small><br>5<br>5<br>0</span></div> | |
<div class="sector"><span><small>$</small><br>4<br>0<br>0</span></div> | |
<div class="sector"><span><small>$</small><br>3<br>0<br>0</span></div> | |
<div class="sector"><span><small>$</small><br>9<br>0<br>0</span></div> | |
<div class="sector"><span><small>$</small><br>5<br>0<br>0</span></div> | |
<div class="sector"><span><small>$</small><br>3<br>0<br>0</span></div> | |
<div class="sector"><span><small>$</small><br>9<br>0<br>0</span></div> | |
<div class="sector"><span>B<br>a<br>n<br>k<br>r<br>u<br>p<br>t</span></div> | |
<div class="sector"><span><small>$</small><br>6<br>0<br>0</span></div> | |
<div class="sector"><span><small>$</small><br>4<br>0<br>0</span></div> | |
<div class="sector"><span><small>$</small><br>3<br>0<br>0</span></div> | |
<div class="sector"><span><span>Lose a</span> t<br>u<br>r<br>n</span></div> | |
<div class="sector"><span><small>$</small><br>8<br>0<br>0</span></div> | |
<div class="sector"><span><small>$</small><br>3<br>5<br>0</span></div> | |
<div class="sector"><span><small>$</small><br>4<br>5<br>0</span></div> | |
<div class="sector"><span><small>$</small><br>7<br>0<br>0</span></div> | |
<div class="sector"><span><small>$</small><br>3<br>0<br>0</span></div> | |
<div class="sector"><span><small>$</small><br>6<br>0<br>0</span></div> | |
</div> | |
</main> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment