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 class="radial-menu">
<ul class="radial-menu__menu-list">
<li class="radial-menu__menu-item">
<div class="radial-menu__menu-link-bg"></div>
<div class="radial-menu__menu-icon">
<span class="oi" data-glyph="bold" title="Bold" aria-hidden="true"></span>
</div>
<div class="radial-menu__menu-content">
<div class="radial-menu__menu-content-wrapper">
<h6 class="radial-menu__menu-content-title">
Bold
</h6>
<p class="radial-menu__menu-content-description">
Make text bold
</p>
</div>
</div>
<a href="javascript:void(0);" class="radial-menu__menu-link"></a>
</li>
<li class="radial-menu__menu-item">
<div class="radial-menu__menu-link-bg"></div>
<div class="radial-menu__menu-icon">
<span class="oi" data-glyph="italic" title="Italic" aria-hidden="true"></span>
</div>
<div class="radial-menu__menu-content">
<div class="radial-menu__menu-content-wrapper">
<h6 class="radial-menu__menu-content-title">
Italic
</h6>
<p class="radial-menu__menu-content-description">
Make text italic
</p>
</div>
</div>
<a href="javascript:void(0);" class="radial-menu__menu-link"></a>
</li>
<li class="radial-menu__menu-item">
<div class="radial-menu__menu-link-bg"></div>
<div class="radial-menu__menu-icon">
<span class="oi" data-glyph="underline" title="Underline" aria-hidden="true"></span>
</div>
<div class="radial-menu__menu-content">
<div class="radial-menu__menu-content-wrapper">
<h6 class="radial-menu__menu-content-title">
Underline
</h6>
<p class="radial-menu__menu-content-description">
Underline text
</p>
</div>
</div>
<a href="javascript:void(0);" class="radial-menu__menu-link"></a>
</li>
<li class="radial-menu__menu-item">
<div class="radial-menu__menu-link-bg"></div>
<div class="radial-menu__menu-icon">
<span class="oi" data-glyph="align-left" title="Align left" aria-hidden="true"></span>
</div>
<div class="radial-menu__menu-content">
<div class="radial-menu__menu-content-wrapper">
<h6 class="radial-menu__menu-content-title">
Text Alignment
</h6>
<p class="radial-menu__menu-content-description">
Set text alignment
</p>
</div>
</div>
<a href="javascript:void(0);" class="radial-menu__menu-link"></a>
</li>
<li class="radial-menu__menu-item">
<div class="radial-menu__menu-link-bg"></div>
<div class="radial-menu__menu-icon">
<span class="oi" data-glyph="list-rich" title="Bulleted List" aria-hidden="true"></span>
</div>
<div class="radial-menu__menu-content">
<div class="radial-menu__menu-content-wrapper">
<h6 class="radial-menu__menu-content-title">
Bulleted List
</h6>
<p class="radial-menu__menu-content-description">
Add a bulleted list
</p>
</div>
</div>
<a href="javascript:void(0);" class="radial-menu__menu-link"></a>
</li>
<li class="radial-menu__menu-item">
<div class="radial-menu__menu-link-bg"></div>
<div class="radial-menu__menu-icon">
<span class="oi" data-glyph="list" title="Numbered List" aria-hidden="true"></span>
</div>
<div class="radial-menu__menu-content">
<div class="radial-menu__menu-content-wrapper">
<h6 class="radial-menu__menu-content-title">
Numbered List
</h6>
<p class="radial-menu__menu-content-description">
Add a numbered list
</p>
</div>
</div>
<a href="javascript:void(0);" class="radial-menu__menu-link"></a>
</li>
<li class="radial-menu__menu-item">
<div class="radial-menu__menu-link-bg"></div>
<div class="radial-menu__menu-icon">
<span class="oi" data-glyph="header" title="Heading" aria-hidden="true"></span>
</div>
<div class="radial-menu__menu-content">
<div class="radial-menu__menu-content-wrapper">
<h6 class="radial-menu__menu-content-title">
Heading
</h6>
<p class="radial-menu__menu-content-description">
Add a heading
</p>
</div>
</div>
<a href="javascript:void(0);" class="radial-menu__menu-link"></a>
</li>
<li class="radial-menu__menu-item">
<div class="radial-menu__menu-link-bg"></div>
<div class="radial-menu__menu-icon">
<span class="oi" data-glyph="double-quote-serif-right" title="Blockquote" aria-hidden="true"></span>
</div>
<div class="radial-menu__menu-content">
<div class="radial-menu__menu-content-wrapper">
<h6 class="radial-menu__menu-content-title">
Blockquote
</h6>
<p class="radial-menu__menu-content-description">
Add a blockquote
</p>
</div>
</div>
<a href="javascript:void(0);" class="radial-menu__menu-link"></a>
</li>
<li class="radial-menu__menu-item">
<div class="radial-menu__menu-link-bg"></div>
<div class="radial-menu__menu-icon">
<span class="oi" data-glyph="link-intact" title="Hyperlink" aria-hidden="true"></span>
</div>
<div class="radial-menu__menu-content">
<div class="radial-menu__menu-content-wrapper">
<h6 class="radial-menu__menu-content-title">
Hyperlink
</h6>
<p class="radial-menu__menu-content-description">
Add a link to something
</p>
</div>
</div>
<a href="javascript:void(0);" class="radial-menu__menu-link"></a>
</li>
<li class="radial-menu__menu-item">
<div class="radial-menu__menu-link-bg"></div>
<div class="radial-menu__menu-icon">
<span class="oi" data-glyph="image" title="Image" aria-hidden="true"></span>
</div>
<div class="radial-menu__menu-content">
<div class="radial-menu__menu-content-wrapper">
<h6 class="radial-menu__menu-content-title">
Image
</h6>
<p class="radial-menu__menu-content-description">
Add an image
</p>
</div>
</div>
<a href="javascript:void(0);" class="radial-menu__menu-link"></a>
</li>
<li class="radial-menu__menu-item" style="display: none;">
<div class="radial-menu__menu-link-bg"></div>
<div class="radial-menu__menu-icon">
<span class="oi" data-glyph="paperclip" title="Attach File" aria-hidden="true"></span>
</div>
<div class="radial-menu__menu-content">
<div class="radial-menu__menu-content-wrapper">
<h6 class="radial-menu__menu-content-title">
Attach File
</h6>
<p class="radial-menu__menu-content-description">
Attach a file
</p>
</div>
</div>
<a href="javascript:void(0);" class="radial-menu__menu-link"></a>
</li>
<li class="radial-menu__menu-item" style="display: none;">
<div class="radial-menu__menu-link-bg"></div>
<div class="radial-menu__menu-icon">
<span class="oi" data-glyph="code" title="Code" aria-hidden="true"></span>
</div>
<div class="radial-menu__menu-content">
<div class="radial-menu__menu-content-wrapper">
<h6 class="radial-menu__menu-content-title">
Code
</h6>
<p class="radial-menu__menu-content-description">
Add some HTML
</p>
</div>
</div>
<a href="javascript:void(0);" class="radial-menu__menu-link"></a>
</li>
<li class="radial-menu__menu-item" style="display: none;">
<div class="radial-menu__menu-link-bg"></div>
<div class="radial-menu__menu-icon">
<span class="oi" data-glyph="eyedropper" title="Font Color" aria-hidden="true"></span>
</div>
<div class="radial-menu__menu-content">
<div class="radial-menu__menu-content-wrapper">
<h6 class="radial-menu__menu-content-title">
Font Color
</h6>
<p class="radial-menu__menu-content-description">
Set font color
</p>
</div>
</div>
<a href="javascript:void(0);" class="radial-menu__menu-link"></a>
</li>
<li class="radial-menu__menu-item" style="display: none;">
<div class="radial-menu__menu-link-bg"></div>
<div class="radial-menu__menu-icon">
<span class="oi" data-glyph="droplet" title="Highlight Color" aria-hidden="true"></span>
</div>
<div class="radial-menu__menu-content">
<div class="radial-menu__menu-content-wrapper">
<h6 class="radial-menu__menu-content-title">
Highlight Color
</h6>
<p class="radial-menu__menu-content-description">
Set font color
</p>
</div>
</div>
<a href="javascript:void(0);" class="radial-menu__menu-link"></a>
</li>
<li class="radial-menu__menu-item" style="display: none;">
<div class="radial-menu__menu-link-bg"></div>
<div class="radial-menu__menu-icon">
<span class="oi" data-glyph="ellipses" title="More" aria-hidden="true"></span>
</div>
<div class="radial-menu__menu-content">
<div class="radial-menu__menu-content-wrapper">
<h6 class="radial-menu__menu-content-title">
More
</h6>
<p class="radial-menu__menu-content-description">
Add more things
</p>
</div>
</div>
<a href="javascript:void(0);" class="radial-menu__menu-link"></a>
</li>
</ul>
<div class="radial-menu__label">
Menu
</div>
</div>
<div class="menu-items-select">
<label class="menu-items-select__label" for="menu-items-to-show">Menu items</label>
<select class="menu-items-select__select" name="menu-items-to-show" id="menu-items-to-show">
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
<option value="6">Six</option>
<option value="7">Seven</option>
<option value="8">Eight</option>
<option value="9">Nine</option>
<option value="10" selected>Ten</option>
<option value="11">Eleven</option>
<option value="12">Twelve</option>
<option value="13">Thirteen</option>
<option value="14">Fourteen</option>
<option value="15">Fifteen</option>
</select>
</div>
<div class="right-click-prompt">
<p class="right-click-prompt__label">
Right click and drag
</p>
</div>
//
// BASIC STYLES
//–––––––––––––––––––––––––––––––––––––
*, *:before, *:after {
box-sizing: border-box;
}
html,
body {
font-family: sans-serif;
// font-family: 'Crete Round', sans-serif;
// font-family: 'Volkhov', sans-serif;
height: 100%;
width: 100%;
}
//
// COLOR
//–––––––––––––––––––––––––––––––––––––
$white: #fff;
$black: #000;
$color-primary: #d4dde5;
$color-primary-lighter: lighten($color-primary, 2%);
$color-primary-lightest: lighten($color-primary, 6%);
$color-primary-darker: darken($color-primary, 2%);
$color-primary-darkest: darken($color-primary, 6%);
$color-secondary: #6d9bc5;
$color-secondary-lighter: lighten($color-secondary, 2%);
$color-secondary-lightest: lighten($color-secondary, 6%);
$color-secondary-darker: darken($color-secondary, 2%);
$color-secondary-darkest: darken($color-secondary, 6%);
//
// MENU
//–––––––––––––––––––––––––––––––––––––
$radial-menu-dimensions: 300px;
$radial-menu-bg: $color-primary-darkest;
// $radial-menu-bg: transparent;
$radial-menu-border-width: 0;
$radial-menu-border-color: transparent;
$radial-menu-item-hovered-bg: $color-secondary;
$radial-menu-item-hovered-border-width: 0;
// $radial-menu-item-hovered-border-color: darken($color-secondary-darkest, 6%);
$radial-menu-item-hovered-border-color: transparent;
//
// LABEL
//–––––––––––––––––––––––––––––––––––––
$radial-menu-label-dimensions: 80px;
$radial-menu-label-font-size: 12px;
$radial-menu-label-font-weight: bold;
$radial-menu-label-bg: $color-primary-lightest;
$radial-menu-label-border-width: 3px;
$radial-menu-label-border-color: $color-primary-darker;
$radial-menu-label-font-color: $color-primary-darkest;
//
// MENU CONTENT
//–––––––––––––––––––––––––––––––––––––
$radial-menu-content-dimensions: 80px;
$radial-menu-content-bg: $color-primary-lightest;
$radial-menu-content-border-width: 3px;
$radial-menu-content-border-color: $color-primary-darker;
$radial-menu-content-bg-hover: $color-secondary-darkest;
$radial-menu-content-border-color-hover: $color-secondary-darkest;
$radial-menu-content-title-font-size: .7em;
$radial-menu-content-title-font-weight: bold;
$radial-menu-content-title-font-color: $white;
$radial-menu-content-description-font-size: .4em;
$radial-menu-content-description-font-weight: normal;
$radial-menu-content-description-font-color: rgba($white, .5);
//
// MENU ICON
//–––––––––––––––––––––––––––––––––––––
$radial-menu-icon-default-transform: translateY(-50%) translateX(-50%);
$radial-menu-icon-dimensions: 25px;
$radial-menu-icon-dimensions-hover: 50px;
$radial-menu-icon-icon-size: 16px;
$radial-menu-icon-icon-size-hover: 21px;
// $radial-menu-icon-bg: darken($color-primary-darkest, 8%);
// $radial-menu-icon-bg-hover: darken($color-primary-darkest, 4%);
// $radial-menu-icon-bg-hover: $white;
// $radial-menu-icon-bg-not-hovered: lighten($radial-menu-icon-bg, 4%);
$radial-menu-icon-bg: transparent;
$radial-menu-icon-bg-hover: transparent;
$radial-menu-icon-bg-hover: transparent;
$radial-menu-icon-bg-not-hovered: transparent;
$radial-menu-icon-color: darken($color-primary-darkest, 16%);
$radial-menu-icon-color-hover: $white;
$radial-menu-icon-color-not-hovered: darken($color-primary-darkest, 8%);
//
// MENU ITEM
//–––––––––––––––––––––––––––––––––––––
$radial-menu-item-default-transform: translateY(-50%);
$radial-menu-item-trapezoid-transform: perspective(200px) rotateY(-77.5deg) scaleX(1.25);
$radial-menu-item-bg: $color-primary-lighter;
// $radial-menu-item-bg-hover: $color-primary-lightest;
$radial-menu-item-bg-hover: $color-secondary;
$radial-menu-item-border-width: 1px;
$radial-menu-item-border-color: $color-primary;
$radial-menu-item-border-color-hover: $color-secondary;
$radial-menu-inset-bg: $color-primary-darkest;
// $radial-menu-inset-bg-hover: darken($color-primary-darkest, 4%);
$radial-menu-inset-bg-hover: $color-secondary;
//
// RADIAL MENU
//–––––––––––––––––––––––––––––––––––––
.radial-menu {
background: $radial-menu-bg;
border: $radial-menu-border-width solid $radial-menu-border-color;
border-radius: 50%;
box-shadow: 0 25px 50px rgba($black, .05);
height: $radial-menu-dimensions;
left: 50%;
opacity: 1;
position: absolute;
top: 50%;
transform: translate(-50%, -50%) scale(1);
transition:
opacity .1s ease,
background .1s ease;
width: $radial-menu-dimensions;
&.is-hidden {
animation-name: scale-down;
animation-duration: .2s;
animation-delay: 0;
animation-iteration-count: 1;
animation-fill-mode: forwards; /* this prevents the animation from restarting! */
animation-timing-function: cubic-bezier(.25, .25, .25, 1.25);
transform: translate(-50%, -50%) scale(0) !important;
opacity: 0;
}
&.is-active {
animation-name: scale-up;
animation-duration: .2s;
animation-delay: 0;
animation-iteration-count: 1;
animation-fill-mode: forwards; /* this prevents the animation from restarting! */
animation-timing-function: cubic-bezier(.25, .25, .25, 1.25);
opacity: 1;
transform: translate(-50%, -50%) scale(1);
}
&.item-is-hovered {
background-color: $radial-menu-item-hovered-bg;
border-color: $radial-menu-item-hovered-border-color;
border-width: $radial-menu-item-hovered-border-width;
}
}
@keyframes scale-up {
0% {
transform: translate(-50%, -50%) scale(0);
}
100% {
transform: translateX(-50%, -50%) scale(1);
}
}
@keyframes scale-down {
0% {
transform: translate(-50%, -50%) scale(1);
}
100% {
transform: translateX(-50%, -50%) scale(0);
}
}
//
// LABEL
//–––––––––––––––––––––––––––––––––––––
.radial-menu__label {
background-color: $radial-menu-label-bg;
border: $radial-menu-label-border-width solid $radial-menu-label-border-color;
border-radius: 50%;
// box-shadow: 0 0 20px rgba(#fff, .2);
color: $radial-menu-label-font-color;
cursor: default;
font-size: $radial-menu-label-font-size;
font-weight: $radial-menu-label-font-weight;
height: $radial-menu-label-dimensions;
left: 50%;
letter-spacing: .1em;
line-height: $radial-menu-label-dimensions - ($radial-menu-label-border-width * 2);
position: absolute;
text-align: center;
text-transform: uppercase;
top: 50%;
transform: translate(-50%, -50%);
width: $radial-menu-label-dimensions;
z-index: 4;
}
.radial-menu {
&.item-is-hovered {
.radial-menu__label {
// transform: translate(-50%, -50%) scale(1.1);
}
}
}
//
// MENU CONTENT
//–––––––––––––––––––––––––––––––––––––
.radial-menu__menu-content {
background-color: $radial-menu-content-bg;
border: $radial-menu-content-border-width solid $radial-menu-content-border-color;
border-radius: 50%;
height: $radial-menu-content-dimensions;
left: 50%;
// opacity: 0;
position: absolute;
text-align: center;
top: 50%;
transform: translate(-50%, -50%);
// transition: all .1s ease;
width: $radial-menu-content-dimensions;
z-index: 1;
}
// Hover.
.radial-menu__menu-item {
&.hovered {
.radial-menu__menu-content {
background-color: $radial-menu-content-bg-hover;
border-color: $radial-menu-content-border-color-hover;
// opacity: 1;
transform: translate(-50%, -50%);
z-index: 4;
}
}
}
.radial-menu__menu-content-wrapper {
padding-left: 10px;
padding-right: 10px;
position: absolute;
top: 50%;
transform: translateY(-50%);
width: 100%;
}
.radial-menu__menu-content-title {
color: $radial-menu-content-title-font-color;
font-size: $radial-menu-content-title-font-size;
font-weight: $radial-menu-content-title-font-weight;
// letter-spacing: .05em;
// margin-bottom: 4px;
line-height: 1.3;
// text-transform: uppercase;
}
.radial-menu__menu-content-description {
color: $radial-menu-content-description-font-color;
display: none;
font-size: $radial-menu-content-description-font-size;
font-weight: $radial-menu-content-description-font-weight;
letter-spacing: .1em;
line-height: 1.3;
text-transform: uppercase;
}
//
// MENU ICON
//–––––––––––––––––––––––––––––––––––––
.radial-menu__menu-icon {
background-color: $radial-menu-icon-bg;
// border-radius: 50%;
// display: none; // OFF
height: $radial-menu-icon-dimensions;
left: 0;
position: absolute;
text-align: center;
top: 0;
transform: $radial-menu-icon-default-transform;
width: $radial-menu-icon-dimensions;
z-index: 2;
.oi {
color: $radial-menu-icon-color;
font-size: $radial-menu-icon-icon-size;
line-height: $radial-menu-icon-dimensions;
transition:
font-size .3s cubic-bezier(.25, .25, .25, 1.5),
color .1s ease;
}
}
// Not hovered.
.radial-menu {
&.item-is-hovered {
.radial-menu__menu-icon {
background-color: $radial-menu-icon-bg-not-hovered;
.oi {
color: $radial-menu-icon-color-not-hovered;
}
}
}
}
// Hovered.
.radial-menu {
&.item-is-hovered {
.radial-menu__menu-item {
&.hovered {
.radial-menu__menu-icon {
background-color: $radial-menu-icon-bg-hover;
height: $radial-menu-icon-dimensions-hover;
width: $radial-menu-icon-dimensions-hover;
.oi {
color: $radial-menu-icon-color-hover;
font-size: $radial-menu-icon-icon-size-hover;
line-height: $radial-menu-icon-dimensions-hover;
}
}
}
}
}
}
//
// MENU LIST
//–––––––––––––––––––––––––––––––––––––
.radial-menu__menu-list {
list-style-type: none;
margin: 0;
padding: 0;
}
//
// MENU ITEM
//–––––––––––––––––––––––––––––––––––––
.radial-menu__menu-item {
display: block;
left: 50%;
position: absolute;
top: 50%;
z-index: 1;
&.hovered {
z-index: 10;
}
}
//
// MENU LINK
//–––––––––––––––––––––––––––––––––––––
.radial-menu__menu-link,
.radial-menu__menu-link-bg {
height: 22px;
padding: 5px 20px;
position: absolute;
transform: $radial-menu-item-default-transform $radial-menu-item-trapezoid-transform;
transform-origin: 0;
transform-style: preserve-3d;
width: 125px;
}
.radial-menu__menu-link {
border-bottom: $radial-menu-item-border-width solid transparent;
border-top: $radial-menu-item-border-width solid transparent;
display: block;
z-index: 3;
}
//
// MENU LINK BG
//–––––––––––––––––––––––––––––––––––––
.radial-menu__menu-link-bg {
background-color: $radial-menu-item-bg;
border-bottom: $radial-menu-item-border-width solid $radial-menu-item-border-color;
border-top: $radial-menu-item-border-width solid $radial-menu-item-border-color;
font-size: 12px;
text-decoration: none;
text-transform: uppercase;
transition: background .1s ease;
z-index: 1;
&:after {
background: $radial-menu-inset-bg;
content: '';
display: none;
// height: 100%;
height: 106%;
right: -1px;
position: absolute;
top: 0;
transition: all .1s ease;
transform: translateY(-3%);
width: 2px;
}
}
// Hover.
.radial-menu__menu-item {
&.hovered {
.radial-menu__menu-link-bg {
background-color: $radial-menu-item-bg-hover;
// border-color: $radial-menu-item-border-color-hover;
// border-width: 0;
border: 0;
&:after {
background: $radial-menu-inset-bg-hover;
height: 106%;
transform: translateY(-3%);
width: 0;
}
}
}
}
//
// MENU ITEM SELECT
//–––––––––––––––––––––––––––––––––––––
.menu-items-select {
bottom: 0;
right: 0;
margin: 0 auto;
padding: 40px;
position: absolute;
// text-align: center;
}
.menu-items-select__label {
color: $color-primary-darkest;
display: block;
font-size: .7em;
font-weight: bold;
letter-spacing: .05em;
margin-bottom: 10px;
text-transform: uppercase;
}
.menu-items-select__select {
appearance: none;
background-color: $color-primary-lightest;
// Black dropdown arrow.
background-image:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA3ppVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTMyIDc5LjE1OTI4NCwgMjAxNi8wNC8xOS0xMzoxMzo0MCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDpjYmU2ZGJmMC0zMWRkLTQyN2EtYjIyYi02YjExMGU5ZDVmODciIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6REM2MzE0REVCNjkzMTFFNkIxODVBOTBFNDM1NDFDOEUiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6REM2MzE0RERCNjkzMTFFNkIxODVBOTBFNDM1NDFDOEUiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENDIDIwMTUuNSAoTWFjaW50b3NoKSI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOmI4YTU2Zjg5LTM0MzAtNDcxNS1iOGQyLWQ5NWM4NzdmYmIyOSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDpjYmU2ZGJmMC0zMWRkLTQyN2EtYjIyYi02YjExMGU5ZDVmODciLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz4RdGokAAAAf0lEQVR42mL8//8/AzUBEwOVwaiBlAMWbIKMjIxEG4CeSujq5fkgB+DBC3E6GR1DARcQX8Zh2HUg5samH5+BIKABxF/QDPsKxLq4HETIQBCIQTMwFZ8PiTEQBGZBDVtKKMiINZATiFcCMS8hAxmxGUBJOmQhRtFo4UBfAwECDADAD7B6p+ae7AAAAABJRU5ErkJggg==');
background-position: 97.5% 50%;
background-repeat: no-repeat;
border: 2px solid $color-primary;
border-radius: 0;
display: block;
font-family: sans-serif;
font-size: .9em;
font-weight: bold;
height: 40px;
padding: 5px 10px;
width: 100px;
}
//
// MENU ITEM SELECT
//–––––––––––––––––––––––––––––––––––––
.right-click-prompt {
bottom: 0;
color: $color-primary-darkest;
font-size: .7em;
font-weight: bold;
left: 50%;
letter-spacing: .05em;
padding: 40px;
position: absolute;
text-transform: uppercase;
transform: translateX(-50%);
}
@media (max-height: 430px) {
.right-click-prompt {
left: 0;
transform: translateX(0);
}
}
//
// BASIC SETUP
//–––––––––––––––––––––––––––––––––––––
var container = document.querySelector('.radial-menu');
var menuDimensions = container.offsetWidth;
var menuItems = container.querySelectorAll('.radial-menu__menu-item');
var menuItemsCount = countMenuItems( menuItems );
//
// COUNT MENU ITEMS
//–––––––––––––––––––––––––––––––––––––
function countMenuItems( elems ) {
// Count elems.
var elemsCount = elems.length;
// Initialise empty counter.
var elemCounter = 0;
for (var i = 0; i < elemsCount; i++) {
var elem = elems[i];
// Get elements current "display" value.
var elemDisplay = elem.currentStyle ? elem.currentStyle.display : getComputedStyle(elem, null).display;
// If the elem is not hidden.
if ( elemDisplay !== 'none' ) {
// Increment the elem counter.
elemCounter++;
}
}
return elemCounter;
}
//
// LINKS
//–––––––––––––––––––––––––––––––––––––
var links = document.querySelectorAll('.radial-menu__menu-link');
setupLinks( links );
setupLinkHovers( links );
//
// LINK BGs
//–––––––––––––––––––––––––––––––––––––
var linkBGs = document.querySelectorAll('.radial-menu__menu-link-bg');
setupLinks( linkBGs );
//
// SETUP LINKS
//–––––––––––––––––––––––––––––––––––––
function setupLinks( elems ) {
// Count elems.
var elemsCount = elems.length;
// var elemsCount = countMenuItems( menuItems );
var menuItems = container.querySelectorAll('.radial-menu__menu-item');
// Count menu items.
var menuItemsCount = countMenuItems( menuItems );
// Find degree interval.
var degreeInterval = 360 / menuItemsCount;
// Loop through elems.
for (var i = 0; i < elemsCount; i++) {
var elem = elems[i];
var parentMenuItem = elem.parentElement;
// Get parent menu item's current "display" value.
var parentMenuItemDisplay = parentMenuItem.currentStyle ? parentMenuItem.currentStyle.display : getComputedStyle(parentMenuItem, null).display;
if ( parentMenuItemDisplay !== 'none' ) {
var phase = i / menuItemsCount;
// console.log('phase(' + i + '): ' + phase);
var theta = phase * 2 * Math.PI;
// console.log('theta(' + i + '): ' + theta);
var cssTransform = 'translateY(-50%) translateZ(0) rotateZ(' + degreeInterval*i + 'deg) perspective(' + menuDimensions/1.5 + 'px)';
var transformString = getLinkTransforms( menuItemsCount );
// cssTransform += 'rotateY(-83.8deg) scaleX(1.38)';
cssTransform += transformString;
// console.log(cssTransform);
elem.style.transform = cssTransform;
}
}
}
//
// ON LINK HOVER
//–––––––––––––––––––––––––––––––––––––
function setupLinkHovers( elems ) {
// Count elems.
var elemsCount = elems.length;
// Loop through elems.
for (var i = 0; i < elemsCount; i++) {
var elem = elems[i];
var parentMenuItem = elem.parentElement;
// Get parent menu item's current "display" value.
var parentMenuItemDisplay = elem.currentStyle ? elem.currentStyle.display : getComputedStyle(elem, null).display;
// If the menu item's display is not set to none.'
if ( parentMenuItemDisplay !== 'none' ) {
elem.addEventListener('mouseenter', function( event ) {
var parentMenuItem = this.parentElement;
parentMenuItem.classList.add('hovered');
container.classList.add('item-is-hovered');
});
elem.addEventListener('mouseleave', function( event ) {
var parentMenuItem = this.parentElement;
parentMenuItem.classList.remove('hovered');
container.classList.remove('item-is-hovered');
});
}
}
}
//
// GET LINK TRANSFORMS
//–––––––––––––––––––––––––––––––––––––
function getLinkTransforms( count ) {
var transformString;
switch (count) {
case 3:
transformString = 'rotateY(-88.012deg) scaleX(1.45)';
break;
case 4:
transformString = 'rotateY(-86.45deg) scaleX(1.425)';
break;
case 5:
transformString = 'rotateY(-85.025deg) scaleX(1.39)';
break;
case 6:
transformString = 'rotateY(-83.65deg) scaleX(1.36)';
break;
case 7:
transformString = 'rotateY(-82.1deg) scaleX(1.325)';
break;
case 8:
transformString = 'rotateY(-80.8deg) scaleX(1.3)';
break;
case 9:
transformString = 'rotateY(-79deg) scaleX(1.265)';
break;
case 10:
transformString = 'rotateY(-77.3deg) scaleX(1.23)';
break;
case 11:
transformString = 'rotateY(-76deg) scaleX(1.21)';
break;
case 12:
transformString = 'rotateY(-74.75deg) scaleX(1.185)';
break;
case 13:
transformString = 'rotateY(-72.1deg) scaleX(1.14)';
break;
case 14:
transformString = 'rotateY(-69.8deg) scaleX(1.11)';
break;
case 15:
transformString = 'rotateY(-67.7deg) scaleX(1.086)';
break;
}
return transformString;
}
//
// ICONS
//–––––––––––––––––––––––––––––––––––––
var icons = document.querySelectorAll('.radial-menu__menu-icon');
var iconDistance = 95;
positionIcons( icons, iconDistance );
function positionIcons( icons, iconDistance ) {
var menuItems = container.querySelectorAll('.radial-menu__menu-item');
// Count menu items.
var menuItemsCount = countMenuItems( menuItems );
// Count icons.
var iconsCount = icons.length;
var iconOffset = 1.575; // Used to rotate 90deg.
// Loop through icons.
for (var i = 0; i < iconsCount; i++) {
var icon = icons[i];
var parentMenuItem = icon.parentElement;
// Get parent menu item's current "display" value.
var parentMenuItemDisplay = parentMenuItem.currentStyle ? parentMenuItem.currentStyle.display : getComputedStyle(parentMenuItem, null).display;
// If the menu item's display is not set to none.'
if ( parentMenuItemDisplay !== 'none' ) {
var phase = i / menuItemsCount;
// console.log('phase(' + i + '): ' + phase);
var theta = phase * 2 * Math.PI;
theta = theta + iconOffset;
// console.log('theta(' + i + '): ' + theta);
icon.style.top = (-iconDistance * Math.cos(theta)).toFixed(1) + 'px';
icon.style.left = (iconDistance * Math.sin(theta)).toFixed(1) + 'px';
}
}
}
//
// RIGHT CLICK
//–––––––––––––––––––––––––––––––––––––
document.addEventListener('contextmenu', function(e) {
e.preventDefault();
var mousePosX = e.clientX;
var mousePosY = e.clientY;
// console.log( 'mousePosX: ' + mousePosX );
// console.log( 'mousePosY: ' + mousePosY );
container.classList.remove('is-hidden');
container.classList.add('is-active');
container.style.top = mousePosY + 'px';
container.style.left = mousePosX + 'px';
mouseMoveListener( mousePosX, mousePosY );
return false;
}, false);
//
// RIGHT CLICK MOUSE UP
//–––––––––––––––––––––––––––––––––––––
document.addEventListener('mouseup', function(e) {
var mouseButton = e.button;
// If it's the right mouse button.
if ( mouseButton == 2 ) {
// Hide the menu.
container.classList.add('is-hidden');
container.classList.remove('is-active');
}
});
//
// MOUSE MOVE LISTENER
//–––––––––––––––––––––––––––––––––––––
function mouseMoveListener(x, y) {
document.addEventListener('mousemove', function(e) {
// If the radial menu is active.
if ( container.classList.contains('is-active') ) {
var newX = e.clientX;
var newY = e.clientY;
var scale = Math.round(Math.sqrt(Math.pow(y - newY, 2) + Math.pow(x - newX, 2)));
// console.log('scale: ' + scale);
scale = scale * 0.01;
// console.log('scale / 100: ' + scale);
// container.style.transform = 'translate(-50%, -50%) scale(' + scale + ')';
// console.log('e.clientX: ' + e.clientX);
// console.log('e.clientY: ' + e.clientY);
}
});
}
//
// MENU ITEMS DROPDOWN
//–––––––––––––––––––––––––––––––––––––
onMenuItemsDropdownChange();
function onMenuItemsDropdownChange() {
// Instantiate the menu items to show select.
var menuItemsSelect = document.getElementById('menu-items-to-show');
// Listen for changes on the select.
menuItemsSelect.addEventListener('change', function(e){
// Get the selected value.
var optionValue = this.value;
// Update menu items accordingly.
updateMenuItemDisplayValues( optionValue );
});
}
//
// UPDATE MENU ITEMS
//–––––––––––––––––––––––––––––––––––––
function updateMenuItemDisplayValues( itemsToShow ) {
var menuItems = container.querySelectorAll('.radial-menu__menu-item');
for (var i = 0; i < menuItems.length; i++) {
if ( i < itemsToShow ) {
menuItems[i].style.display = 'block';
} else {
menuItems[i].style.display = 'none';
}
}
// Set up links.
var links = document.querySelectorAll('.radial-menu__menu-link');
setupLinks( links );
setupLinkHovers( links );
// Set up link BGs.
var linkBGs = document.querySelectorAll('.radial-menu__menu-link-bg');
setupLinks( linkBGs );
// Set up icons.
var icons = document.querySelectorAll('.radial-menu__menu-icon');
var iconDistance = 95;
positionIcons( icons, iconDistance );
}
Also see: Tab Triggers