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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
- var $icons = ['insert_comment', 'account_circle', 'directions', 'help', 'find_in_page']
h1 Animated dial buttons
p Click to see different variants 🤓
each $val, $style in {'full': 5, 'half': 4, 'left-half': 4, 'right-half': 5, 'bottom-half': 5, 'top-half': 4, 'top-left': 3, 'top-right': 3, 'bottom-left': 3, 'bottom-right': 3}
.loading-bay(class=`loading-bay--${$style}`)
.dial-btn__container(class=`dial-btn__container--${$style}`, data-options= $val)
button.dial-btn
i.material-icons add
- var n = 1
while n < ($val + 1)
button.dial-btn.dial-btn--option(data-option= n)
i.material-icons= $icons[n - 1]
- n++
$ns = dial-btn
$containerEl = container
$optionMod = option
$activeMod = active
/**
* Number of options plays an important part in having variations of content
* but retaining the correct behaviour with regards to correct projection
* angles.
*
* Instances where we don't care about calculating the position we can just
* refer to an upper bound limit and cover the cases.
*/
$noOfOptionsLimit = 5
$btnSize = 40px
$subBtnSize = 30px
$layoutRadius = 45px
$transitionSpd = .25s
$transitionStp = .1s
/**
* Use modifiers to define ranges for our positions
*
* NOTE: 0 Actually starts at 3 o'clock so to get for example
* left-sided half circle do 90 - 270
*
* IMPORTANT NOTE: You'll seriously want to reduce the amount of ranges
* if you were to use this in prod because the amount of generated CSS is
* large to cover all scenarios
*/
$ranges = {
full: {
start: 0,
end: 360
},
half: {
start: 0,
end: 180
},
left-half: {
start: 90,
end: 270
},
right-half: {
start: 270,
end: 90
},
bottom-half: {
start: 0,
end: 180
},
top-half: {
start: 180,
end: 360
},
top-left: {
start: 180,
end: 270
},
top-right: {
start: 270,
end: 360
},
bottom-left: {
start: 90,
end: 180
},
bottom-right: {
start: 0,
end: 90
}
}
/**
* Get true position based on area of circle we want to use.
* Default is to use full circle but could you use top, bottom, left, right
* halves or even quadrants based on the angle range we use.
*
* Given start and endpoints dictate the range in which we can project
* positions.
*/
getPosition($options, $idx, $start, $end)
$range = $end - $start
if ($range < 360 && $options > 1)
$options = $options - 1
$angle = $start + ($range / ($options)) * ($idx - 1)
xPos = $layoutRadius * cos($angle * (PI / 180))
if $start > $end
xPos = -(xPos)
yPos = $layoutRadius * sin($angle * (PI / 180))
(xPos yPos)
generatePositions($start, $end)
for num in (1..$noOfOptionsLimit)
&[data-options=\'{num}\']
.{$ns}--{$activeMod} ~ .{$ns}--{$optionMod}
for opt in (1..(num + 1))
&:nth-of-type({opt})
$idx = opt - 1
$range = get($ranges, full)
$pos = getPosition(num, $idx, $start, $end)
transform translate($pos[0], $pos[1])
.{$ns}
border-radius $btnSize
border none
z-index $noOfOptionsLimit + 2
position absolute
top 0
left 0
height $btnSize
width $btnSize
&--{$optionMod}
position absolute
height $subBtnSize
width $subBtnSize
border-radius $subBtnSize
top 50%
left 50%
margin-left -($subBtnSize / 2)
margin-top -($subBtnSize / 2)
transform translate(0, 0)
transition transform $transitionSpd ease 0s
/**
* Increase the loop because first button is the primary
*/
for num in 2..($noOfOptionsLimit + 1)
&:nth-of-type({num})
z-index num
transition-delay (num * $transitionStp)
&__{$containerEl}
display inline-block
position relative
height $btnSize
width $btnSize
border-radius $btnSize
/**
* Generate the various styles and mutations
*/
for $mod in $ranges
&--{$mod}
$start = $ranges[$mod].start
$end = $ranges[$mod].end
generatePositions($start, $end)
/**
* Themeing
*/
*
box-sizing border-box
animation fadeIn .5s
body
background-color #222222
color #fafafa
text-align center
.loading-bay
width 200px
height 200px
border 2px solid silver
border-radius 20px
position relative
display inline-block
margin 10px
overflow hidden
background-color #333
&:before
display block
position absolute
top 0
left 0
color white
font-size 18px
padding 5px
.dial-btn__container
position absolute
top 50%
left 50%
margin-left -($btnSize / 2)
margin-top -($btnSize / 2)
.dial-btn
outline 0
cursor pointer
&:not(.dial-btn--option)
color #fafafa
i
font-size 24px
transition transform .25s ease 0s
transform rotate(0deg)
position absolute
top 50%
left 50%
margin-left -12px
margin-top -12px
&--active
i
transform rotate(45deg)
&--option
font-size 18px
font-weight normal
i
font-size 18px
line-height 18px
margin-left -9px
margin-top -9px
$colors = #f44336 #FF5722 #FFC107 #4CAF50 #009688 #00BCD4 #2196F3 #3F51B5 #673AB7 #E91E63
for $style in $ranges
.loading-bay
&--{$style}
&:before
content $style
for $demo in (1..10)
.loading-bay
&:nth-of-type({$demo})
&:before
.dial-btn:not(.dial-btn--option)
background-color $colors[$demo - 1]
@keyframes fadeIn
from
opacity 0
to
opacity 1
;(function(){
const CLASSES = {
BTN : 'dial-btn',
ACTIVE: 'dial-btn--active',
OPTION: 'dial-btn--option'
};
var btns = document.querySelectorAll(`.${CLASSES.BTN}:not(.${CLASSES.OPTION})`);
var toggleActive = function(e) {
const btn = e.currentTarget;
var processClick = function(evt) {
if (e !== evt) {
btn.classList.remove(CLASSES.ACTIVE);
btn.IS_ACTIVE = false;
document.removeEventListener('click', processClick);
}
}
if (!btn.IS_ACTIVE) {
btn.IS_ACTIVE = true;
btn.classList.add(CLASSES.ACTIVE);
document.addEventListener('click', processClick);
}
};
/* Bind primary buttons */
[].map.call(btns, function(btn) {
btn.addEventListener('click', toggleActive);
});
/* Bind a random listener to ensure underlying action would still be called */
const randomBtns = document.querySelectorAll(`.${CLASSES.OPTION}`);
[].map.call(randomBtns, function(btn) {
btn.addEventListener('click', function(e) {
console.info(`Clicked ${e.currentTarget.getAttribute('data-option')}`);
});
});
})();
Also see: Tab Triggers