Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Drag the red arrow to choose your food</h1>
<p id=orderOptionSelectedName>Donut</p>
<br>
<div id=orderPicker>
	<div id=orderPickerOptionsWrapper>
		<img src="Dunking/128/Donut_2.png" data-name="Donut" style="width:90px; top:20px; left: calc(50% - 40px);"/>
		<img src="ie_yummy/128/cake_7.png" data-name="Pie" style="right: 20px; top: calc(50% - 40px);"/>
		<img src="ie_yummy/128/cake_20.png" data-name="Cake" style="bottom: 20px; left: calc(50% - 40px);"/>
		<img src="ie_yummy/128/cake_15.png" data-name="Cupcake" style="left: 20px; top: calc(50% - 40px);"/>
	</div>
	<div id=orderPickerArrowWrapper>
		<div id=orderPickerArrow></div>
	</div>
</div>
<p id=credit>✰ Icons by IconBlock and IconEden via Iconfinder.</a></p>
              
            
!

CSS

              
                #orderPicker {
	--orderPickerSize: 250px;
	width: var(--orderPickerSize); height: var(--orderPickerSize);
	margin: auto; margin-top: 60px;
	position: relative;
	border-radius: 50%;
	box-shadow: inset 0 0 10px 0 hsl(210,25%,60%);
	background-color: beige;
}
#orderPicker::before{
	width: 120%; height: 120%;
	background-image: linear-gradient(45deg, deeppink 30% , gold);
	content: ''; 
	border-radius: 50%;
	z-index: -1;
	position: absolute; left: -10%; top: -10%;
}

#orderPickerOptionsWrapper, #orderPickerArrowWrapper {
	width: 100%; height: 100%;
	position: absolute;
}

#orderPickerOptionsWrapper,#orderOptionSelectedName{
	user-select: none; -webkit-user-select: none; -moz-user-select: none;
}

#orderPickerOptionsWrapper > img {
	width: 75px;
	position: absolute;
	transition: width .5s cubic-bezier(.8,-.5,.2,1.4);
}
/* individual image placement is done inline, so see the HTML for that */

#orderPickerArrow{
	width: 0; height: 0;
	border-left: 20px solid transparent;
	border-right: 20px solid transparent;
	border-top: 20px solid crimson;
	transform: translateX(calc( var(--orderPickerSize) / 2 - 20px));
	cursor: pointer;
}

#orderOptionSelectedName {
	width: 200px; height: 35px;
	margin: auto;
	font-size: 18pt;
	box-shadow: inset 0 0 5px 0 hsl(210,25%,60%);
	background-color: beige;
	border-radius: 5px;
}

h1, #orderOptionSelectedName {
	text-align: center;
}

h1 {
	color: beige;
	text-shadow: 1px 1px 0 #000;
}

body {
	font-family: 'Crimson Text', serif;
	background: linear-gradient(45deg, gold 50%, deeppink 50%);
	height: 100vh;
}

#credit{
	text-align: center;
	font-size: 14pt;
	color: crimson;
	text-shadow: 1px 1px beige;
	margin-top: 100px;
	width: 100%;
}

@media (max-width: 420px){
	h1, #credit{
		display: none;
	}
}
              
            
!

JS

              
                const pickerOptions = document.querySelectorAll('#orderPickerOptionsWrapper > img');
// get the list of angles that delimit the options in the picker
const øArray = [];
for(i=0, ø=(2 * Math.PI)/pickerOptions.length; i<pickerOptions.length; i++)
		øArray[i]=(i*ø) - (ø/2);


// add mouse event listeners 
const arrow = document.querySelector('#orderPickerArrow');
arrow.addEventListener('mousedown', () => {document.addEventListener('mousemove', onMouseMove)});
arrow.addEventListener('touchmove', () => {document.addEventListener('touchmove', onMouseMove)});
document.addEventListener('mouseup',() => {
	document.body.style.cursor = 'default';
	if(document.onmousemove !== undefined) document.removeEventListener('mousemove',onMouseMove);
})
document.addEventListener('touchend',() => {
	if(document.onmousemove !== undefined) document.removeEventListener('touchmove',onMouseMove);
})


// get the coordinates of the picker's topmost point (where the arrow resides at the beginning) – this will be the reference point for rotating the arrow later
const picker = document.querySelector('#orderPicker');
const pickerStyle = getComputedStyle(picker);
const x = picker.offsetLeft + (parseInt(pickerStyle['width'], 10) / 2);
const y = picker.offsetTop + (parseInt(pickerStyle['height'], 10) / 2);


const arrowWrapper = document.querySelector('#orderPickerArrowWrapper');
const optionWidth = pickerOptions[1].style.width;
const label = document.querySelector('#orderOptionSelectedName');
const pickerOptionsArray = Array.prototype.slice.call(pickerOptions);
/* The function to rotate arrow */
function onMouseMove(evt){
	// calculate the angle for the rotation, then rotate the arrow
	let ø = 0;
	if(evt.type=='touchmove')
		ø = -1 * Math.atan2(evt.touches[0].clientX - x, evt.touches[0].clientY - y) + Math.PI;
	else
		ø = -1 * Math.atan2(evt.clientX - x, evt.clientY - y) + Math.PI;
	arrowWrapper.style.transform = `rotate(${ø}rad)`;
	// remove any option's zoom in style
	let zoomedEle = pickerOptionsArray.find(element => {return element.style.width != optionWidth})
	if(zoomedEle) zoomedEle.style.width = optionWidth;
	// find the option the arrow rotated to and zoom in on it to select
	let i = øArray.indexOf(øArray.reduce((accumulator, currentValue)=>{
		if (currentValue<=ø && currentValue>=accumulator) return currentValue;
		else return accumulator;
	}));
	pickerOptions[i].style.width= '90px';
	// update the label (at the top of the picker) with the selected option
	label.textContent = pickerOptions[i].dataset.name;
}
              
            
!
999px

Console