HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div id="wheel-container">
<div id="wheel">
<div id="wi1" data-color="red" class="wheel-item wi1"></div>
<div id="wi2" data-color="yellow" class="wheel-item wi2"></div>
<div id="wi3" data-color="green" class="wheel-item wi3"></div>
<div id="wi4" data-color="purple" class="wheel-item wi4"></div>
<div id="wi5" data-color="blue" class="wheel-item wi5"></div>
<div id="wi6" data-color="turqoise" class="wheel-item wi6"></div>
<div id="wi7" data-color="orange" class="wheel-item wi7"></div>
<div id="wi8" data-color="pink" class="wheel-item wi8"></div>
</div>
</div>
body {
padding: 0;
margin: 0;
overflow-x: hidden;
}
#display-text {
font-size: 50px;
font-weight: 900;
margin: 0 auto;
display: block;
width: 100%;
border-bottom: 5px solid red;
}
$containerHeight: 300;
$containerWidth: $containerHeight / 5 * 4;
$containerWidth: $containerHeight;
#wheel-container {
position: absolute;
height: $containerHeight * 1px;
width: $containerWidth * 1px;
right: 0;
bottom: 0;
transform: translate(50%, 50%);
overflow: hidden;
padding: 50px;
left: 0;
top: 20px;
transform: none;
}
#wheel {
//background-color: black;
position: relative;
height: $containerHeight * 1px;
width: $containerWidth * 1px;
&:hover {
cursor: pointer;
}
.wheel-item {
width: 25%;
height: 45%;
float: left;
background-color: #333;
//border: 2px solid red;
z-index: 1;
position: absolute;
//left: 400px;
left: 50%;
top: 50%;
transition: all .2s ease-in-out;
border-radius: 25px;
transform-origin: 50% -1px;
$colorArr: (
red,
yellow,
green,
purple,
blue,
aqua,
orange,
pink,
);
$wheelitems: 8;
$classSlug: wi !default;
@for $i from 1 through $wheelitems {
$deg: 180 + ($i - 1) * 45deg;
&.wi#{$i} {
transform: rotate(#{$deg});
z-index: 9 - $i;
background: nth($colorArr, $i);
&.active {
transform: rotate(#{$deg}) scale(1.18);
z-index: 200;
}
}
}
}
}
// card highlight corner
// top-left, top-right, bottom-right, bottom-left
// default: top-left;
var cardHighlight = 'default';
// caching of the container we're building our circle in
var wheel = $('#wheel');
// number of children the container has
var wheelChildren = wheel.children().length;
// snap degree locations - circle is 360deg, wheelChildren is the number of items we have
var rotationSnap = 360/wheelChildren;
var myDraggable;
var clockwise;
var lastRotation = 0;
var overshoot = false;
TweenLite.set(wheel, {xPercent: 0, yPercent: 0});
var transform = wheel[0]._gsTransform;
// function being executed when a card has been chosen and not changed for x seconds
function executeAfterCardChosen(updateText) {
$('#display-text').text(updateText);
}
// delay after dragging the rotatatatata before executing the defined action
// that is supposed to happen after an element has been selected
var executionDelay = 1.5;
// the variable holding the timeout trigger made globally available
var timeOutTrigger;
var closestElem;
function activateClosestCard() {
$('.wheel-item').removeClass('active');
// save wheel width and height
var wheelWidth = wheel.width();
var wheelHeight = wheel.height();
// default offset is top left
var cardHighlightOffset = $('#wheel').offset();
// if another hightlighting type is chosen
if(cardHighlight == 'top-right') {
cardHighlightOffset = {left: wheelWidth + cardHighlightOffset.left, top: cardHighlightOffset.top};
}
else if(cardHighlight == 'bottom-left') {
cardHighlightOffset = {left: cardHighlightOffset.left, top: cardHighlightOffset.top + wheelHeight};
}
else if(cardHighlight == 'bottom-right') {
cardHighlightOffset = {left: wheelWidth + cardHighlightOffset.left, top: wheelHeight + cardHighlightOffset.top + 50};
}
closestElem = $('.wheel-item').closestToOffset(cardHighlightOffset);
closestElem.addClass('active');
}
function init()
{
myDraggable = Draggable.create(wheel, {
type: "rotation",
throwProps: true,
minDuration: .5,
maxDuration: 1,
throwResistance: 1000,
overshootTolerance: 1,
snap: function(endValue) {
return Math.round(endValue / rotationSnap) * rotationSnap;
},
// after snapping is completed
onThrowComplete: function() {
activateClosestCard();
timeOutTrigger = setTimeout(
function() {
executeAfterCardChosen(closestElem.prop('id'));
},
executionDelay * 1000
);
},
// once dragging starts - not click!
onDragStart: function() {
$('.wheel-item.active').removeClass('active');
clearTimeout(timeOutTrigger);
timeOutTrigger = null;
},
// while dragging, event fires ~10 times per second
onDrag: function() {
activateClosestCard();
},
/*onDragEnd: function() {
console.log('dragend!!!');
},
onRelease: function() {
console.log('release!!!');
},
onLockAxis: function() {
console.log('lockaxis');
},
onThrowUpdate: function() {
console.log("update!!!");
},
onComplete: function() {
console.log("complete!");
},*/
});
}
// initialise circle
init();
jQuery.fn.closestToOffset = function(offset) {
var el = null,
elOffset,
x = offset.left,
y = offset.top,
distance,
dx,
dy,
minDistance;
this.each(function() {
var $t = $(this);
elOffset = $t.offset();
right = elOffset.left + $t.width();
bottom = elOffset.top + $t.height();
if (
x >= elOffset.left &&
x <= right &&
y >= elOffset.top &&
y <= bottom
) {
el = $t;
return false;
}
var offsets = [
[elOffset.left, elOffset.top],
[right, elOffset.top],
[elOffset.left, bottom],
[right, bottom],
];
for (var off in offsets) {
dx = offsets[off][0] - x;
dy = offsets[off][1] - y;
distance = Math.sqrt(dx * dx + dy * dy);
if (minDistance === undefined || distance < minDistance) {
minDistance = distance;
el = $t;
}
}
});
return el;
};
var wheelTransformArray = [
'rotate(360deg)',
'rotate(315deg)',
'rotate(deg)',
'rotate(deg)',
'rotate(deg)',
'rotate(135deg)',
'rotate(deg)',
'rotate(deg)',
];
$('.wheel-item').click(function() {
var index = $(this).index();
var rotateDeg = 360 - (45 * index);
console.log(index);
TweenMax.to($('#wheel'), 1, {transform: 'rotate(' + rotateDeg + 'deg)'});
});
Also see: Tab Triggers