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.
<div id="cookies-module">
<section>
<h3>This Website Uses Cookies</h3>
<p>Cookies are small data files we use to improve your experience, such as saving your preferences or showing you personalized ads. Turn this off at any time by using this switch, or visit our <a href="#">Cookie Policy</a> page for more info.</p>
</section>
<section>
<div class="content">
<h4>Cookies: <span id="cookie-status">ON</span></h4>
<div>
<p class="on-content">You consent to us setting cookies in accordance with our <a href="#">Cookie Policy</a>.</p>
<p class="off-content">We are not tracking or saving any data while you use this site.</p>
</div>
</div>
<div id="cookie-toggle">
<div id="track">
<p class="on">ON</p>
<p class="off">OFF</p>
</div>
<div id="plate">
<span></span>
<div id="cookie-svg">
<div>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="100px" height="100px" viewBox="0 0 100 100" enable-background="new 0 0 100 100" xml:space="preserve">
<g id="middle-crumb">
<polygon fill="#C3996B" points="27.7,45.6 34.6,44.4 34.3,40.8 32.2,38.3 25.6,39.7 "/>
<polygon fill="#754C28" points="27.3,43.9 30.1,44.4 31.1,40.1 28.2,39 25.6,41.4 "/>
</g>
<g id="bottom-pieces">
<polygon fill="#C3996B" points="73.1,63 73.6,61.2 80.3,61.5 82.5,63.8 82.5,65.5 79,66.1 75.3,65.3 "/>
<polygon fill="#C3996B" points="85.3,67.7 85.8,65.4 85,64 82.1,64.2 82.1,66.8 83.5,67.7 "/>
<polygon fill="#C3996B" points="85.4,66.1 85.3,67.3 87,67.7 86.5,66.5 85.7,65.9 "/>
<polygon fill="#C3996B" points="81.6,65.9 81.6,65.4 82.3,65.3 82.2,66.4 81.8,66.4 "/>
<polygon fill="#C3996B" points="81.2,65.9 81.2,65.6 81.6,65.5 81.8,65.9 81.8,66.4 81.1,66.2 "/>
<polygon fill="#C3996B" points="80.4,65.6 80.3,66 80.7,66.2 81.3,66.1 81.3,65.6 80.8,65.5 "/>
<polygon fill="#C3996B" points="73.6,63.9 74,63.8 74.5,64.1 74.4,64.5 73.6,64.2 "/>
</g>
<g id="top-wedge">
<polyline fill="#C3996B" points="1.9,45.2 0,39.8 3,30.9 9.1,23.7 9.5,23.5 12.4,19.4 13.1,18 17.3,10.4 23.2,9.3 29,5.9 33.4,2 43.7,0.4 45.3,1.1 50.8,0.8 57.6,1.2 62.9,0 68.3,3.9 76,7.8 87.3,13.6 90.7,21.3 93.8,26.2 85.5,27.4 73.1,33.2 66.7,39 64.2,38.7 54.8,40 50.5,42.2 47.4,42.3 42.6,40.3 36.6,39.6 "/>
<g>
<polygon fill="#754C28" points="25,35.4 19.1,40.7 22.2,43.4 27,41.3 32.6,40.6 31.7,37 "/>
<polygon fill="#754C28" points="48.5,24.2 48,29 53.1,31.2 56,26.9 52.7,24.1 "/>
<polygon fill="#754C28" points="75.8,14.9 68.7,16.3 67.1,23.9 73.9,25.5 78.1,21.3 "/>
<polygon fill="#754C28" points="28.2,16.5 30.9,22.3 35.5,21 36.2,16.8 33.4,13.8 "/>
</g>
</g>
<g id="top-pieces">
<polygon fill="#C3996B" points="61.9,37.1 63.1,38.4 66.7,39 68.8,38.1 70.6,35.7 69.8,33.4 65.6,33.4 61.9,35.5 "/>
<polygon fill="#C3996B" points="70.8,32 69.3,34.1 70.8,35.7 72.6,34.3 73.1,33.2 "/>
<polygon fill="#C3996B" points="61.2,37.1 63.1,37.2 63.7,38.5 62.8,39.1 61,39 60.9,37.6 "/>
<polygon fill="#C3996B" points="61.6,36.1 62.5,36.4 62.7,37.4 62.2,37.6 61.4,37.3 "/>
<polygon fill="#C3996B" points="60.5,37.9 61.2,37.6 61.5,38.1 61.4,39 60.3,39 60.2,38.2 "/>
<polygon fill="#C3996B" points="73.2,31.7 72.4,32 71.8,33.1 72.9,33.5 74.3,32.8 "/>
<polygon fill="#C3996B" points="74,31.9 73.5,32.2 73.5,32.5 73.9,32.7 74.5,32.7 75,32.3 "/>
</g>
<g id="bottom-wedge">
<polygon fill="#C3996B" points="1.9,45.2 1.7,50.3 2.2,57.4 1.1,59.1 0.2,65.5 3.9,67.5 5.6,71.6 7.3,73.2 14,83.1 14.7,87.9 19.4,88.4 19.4,88.4 28.6,94.4 37.2,99.7 43.9,99.3 50.8,99.8 56.3,99.5 60.9,100 66,97.4 72.4,94.8 79.6,92.2 82.6,88.1 88.5,82 88.8,81.8 98.4,70.6 94.8,70.3 92.8,71.3 90.8,70.5 88.8,69.3 86.9,67.6 85.3,67.2 85.2,67.6 83.6,67.5 82.2,66.3 80.4,65.8 79.1,66 75.3,65.3 73.2,63 73.6,61.8 70.7,58.3 67.1,56.8 60.2,51.1 56.6,50.7 55.3,50.1 51.1,45.4 47.9,43.8 46.9,41.9 42.7,40.2 36.6,39.5 14.6,42.8 "/>
<g>
<polygon fill="#754C28" points="35,80.1 34.5,83.8 41.9,85.6 43.5,78.7 39.3,77.7 "/>
<polygon fill="#754C28" points="37,59.8 37,65.4 45.5,66.6 49,61 43.7,56.4 "/>
<polygon fill="#754C28" points="61.6,75.6 61,81.2 68.5,82.8 70,80.3 67.4,74.4 "/>
<polygon fill="#754C28" points="15.6,61 14.6,66.2 18.6,68.9 22.6,64.7 20.2,61.9 "/>
<polygon fill="#754C28" points="26.3,39.4 20.5,41.9 26.9,47.4 33.1,42.9 32.1,38.7 "/>
</g>
</g>
<g id="right-wedge">
<polygon fill="#C3996B" points="98.4,70.6 100,59.1 99.6,56.9 99.6,56.9 100,50.3 99.8,46 100,41.7 97.9,36.1 97.6,35.1 97.4,32.6 97.6,28.4 94.9,26.3 93.8,26.2 85.1,26.8 77.1,31.1 72.9,33.2 67.2,38.6 64.1,38.3 54.5,39.6 50.6,41.7 46.9,41.9 47.7,44 51,45.5 55.2,50.2 56.6,50.8 60.2,51.2 67,56.9 70.6,58.4 73.5,61.8 80.1,61.9 82.1,64.2 84.6,64.3 86.2,67.1 88.7,69.4 90.8,70.6 92.8,71.5 94.9,70.4 "/>
<g>
<polygon fill="#754C28" points="75.8,36.7 77.5,39.6 84.3,41.5 85.8,34.7 78.5,34.3 "/>
<polygon fill="#754C28" points="59.8,47.6 59.8,53.6 66.5,55.5 69.8,49.5 63.2,45.9 "/>
<polygon fill="#754C28" points="87.4,53 83.9,57.7 88.2,62.2 93.9,60.6 93.9,53 "/>
</g>
</g>
</svg>
</div>
</div>
</div>
</div>
</section>
</div>
<header>
<a id="profile-icon" href="http://www.twitter.com/dsenneff" target="_blank"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/128542/avatar.jpg" alt="Profile photo of Darin Senneff" /></a>
<button id="cookie-icon" class="active"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/128542/cookie-icon.svg" alt="Cookie Toggle" /></button>
</header>
/* import webfonts */
@import url('https://rsms.me/inter/inter.css');
/* vars */
$inter: 'Inter', sans-serif;
$brown: #754c28;
$coal: #231f20;
$yellow: #f9efa7;
$yellow-light: #f9f4d4;
$status-on: #0e8a4d;
$status-off: #93362c;
/* mixins */
@mixin breakpoint($point) {
@media (max-width: $point + "px") { @content ; }
}
html {
color: $coal;
font-family: $inter; font-size: 1em; line-height: 1.4;
-webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
height: 100%;
}
body {
background-color: #f1f1f2;
position: relative;
height: 100%;
}
header {
padding: 0rem 2rem;
width: 100%; height: 5rem;
box-sizing: border-box;
background-color: white;
box-shadow: 0 2px 0 rgba(0,0,0,0.15);
position: relative; z-index: 2;
display: flex; flex-flow: row nowrap; justify-content: space-between; align-items: flex-start;
#profile-icon {
margin: 0; padding: 1rem 0;
img {
width: 3rem; height: 3rem;
display: block; box-sizing: border-box;
border-radius: 50%; border: solid 1px #FFF;
}
}
#cookie-icon {
margin: 0; padding: 1.75rem 1rem .75rem; box-sizing: border-box;
height: auto; display: flex; flex-flow: row nowrap; align-items: center;
background-color: white;
position: relative;
outline: none;
border: none; border-bottom-left-radius: 8px; border-bottom-right-radius: 8px;
transition: background-color .5s ease;
&:hover {
/*background-color: #f0f0f0;*/
}
img {
width: 1.5rem; height: 1.5rem;
vertical-align: middle;
}
&:after {
margin: 0 0 0 .5rem;
content: "";
width: 0;
height: 0;
border-style: solid;
border-width: 6px 5px 0 5px;
border-color: #231f20 transparent transparent transparent;
transition: transform .25s ease;
}
&.active {
background-color: $yellow;
&:after {
transform: rotate(180deg);
}
}
}
@include breakpoint(600) {
padding: 0 1rem;
}
}
#cookies-module {
margin: 0; padding: 0 2rem; box-sizing: border-box;
width: 100%;
overflow: hidden;
position: relative;
background-color: $yellow;
display: flex; flex-flow: row nowrap; justify-content: space-between; align-items: flex-start;
h3 {
margin: 0 0 .5rem; padding: 0;
font-family: $inter; font-size: 1.125rem; font-weight: 700; color: $brown;
}
h4 {
margin: 0 0 .25rem; padding: 0;
font-family: $inter; font-size: 1rem; font-weight: 700; color: $coal;
#cookie-status {
color: $status-on;
transition: color .25s ease;
}
}
p {
margin: 0 0 1rem; padding: 0;
font-family: $inter; font-size: .875rem; font-weight: 400; color: $coal;
line-height: 150%;
&:last-of-type {margin-bottom: 0;}
a {color: $brown;}
}
section:first-of-type {
margin: 1.75rem 2rem 1.75rem 0;
}
section:last-of-type {
margin: .75rem 0; padding: 1rem; box-sizing: border-box;
width: 40%;
background-color: $yellow-light;
border-radius: 8px;
/*box-shadow: 0 2px 0 rgba(0,0,0,0.15);*/
border: dashed 1px #dbc877;
flex: 0 0 auto;
display: flex; flex-flow: row nowrap; justify-content: space-between; align-items: flex-start;
.content {
margin: 0 2rem 0 0;
width: 100%;
p {margin: 0;}
.on-content {
display: block;
}
.off-content {
display: none;
}
}
#cookie-toggle {
width: 150px; height: 100px;
position: relative;
flex: 0 0 auto;
/*position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);*/
#plate {
width: 100px; height: 100px;
position: absolute; top: 50%; right: 0%; transform: translate(0,-50%); z-index: 0;
background-image: radial-gradient(50% 50%, #E6E6E6 50%, #FFFFFF 100%);
background-image: none;
background: #FFF;
border-radius: 50%;
box-shadow: -3px 5px 0 rgba(0,0,0,0.1);
transition: box-shadow .5s ease;
span {
width: 67%; height: 67%;
background-color: #F2F2F2; border-radius: 50%;
background-image: radial-gradient(50% 50%, #FFFFFF 50%, #F2F2F2 100%);
position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
}
&:before, &:after {
content: "";
border: solid .5px #76acd6; border-radius: 50%;
position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
transition: border-color .5s linear;
}
&:before {
content: "";
width: 89%; height: 89%;
}
&:after {
content: "";
width: 94%; height: 94%;
}
#cookie-svg {
width: 67%;
position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); z-index: 1;
pointer-events: none;
div {
padding-bottom: 100%;
width: 100%; height: 0;
position: relative;
svg {
width: 100%; height: 100%;
position: absolute; top: 0; left: 0;
overflow: visible;
* {
/*fill: #C3996B;*/
}
}
}
}
}
#track {
width: 100%; height: 50px;
border-radius: 25px;
position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
overflow: hidden;
/*background-image: linear-gradient(0deg, #1AEF85 0%, #1DC675 100%);*/
background-image: linear-gradient(0deg, #14E27C 0%, #11B867 100%);
&:before {
content: "";
position: absolute; top: 0; left: 0;
width: 100%; height: 100%;
background-image: linear-gradient(0deg, #E2E2E2 0%, #B8B8B8 100%);
opacity: 0;
transition: opacity .5s ease-out;
}
p {
margin: 0; padding: 0;
font-size: .75rem; font-weight: bold;
text-transform: uppercase; color: #FFF; line-height: 100%; text-align: center;
display: inline-block;
position: absolute; top: 50%; transform: translateY(-50%);
width: calc(100% - 100px);
transition: opacity .5s ease-out;
pointer-events: none;
&.on {
left: 0px; opacity: 1;
}
&.off {
right: 0px; opacity: 0;
color: $coal;
}
}
&.off {
}
}
}
}
&.off {
h4 {
#cookie-status {
color: $status-off;
}
}
section:last-of-type {
.content {
.on-content {
display: none;
}
.off-content {
display: block;
}
}
#cookie-toggle {
#plate {
box-shadow: 3px 5px 0 rgba(0,0,0,0.1);
/*transform: translate(-50px,-50%);*/
&:before, &:after {border-color: $status-off;}
}
#track {
&:before {opacity: 1;}
p {
&.on {opacity: 0;}
&.off {opacity: 1;}
}
}
}
}
}
@include breakpoint(900) {
section:last-of-type {
width: 50%;
}
}
@include breakpoint(700) {
section:last-of-type {
flex-flow: row wrap; justify-content: center;
.content {
div {
margin: 0 0 1rem;
}
}
}
}
@include breakpoint(600) {
padding: 0 1rem;
flex-flow: row wrap;
section:first-of-type {
margin: 1.75rem 0rem .5rem 0;
width: 100%;
flex: 0 0 auto;
}
section:last-of-type {
flex-flow: row nowrap; justify-content: flex-start;
width: 100%;
flex: 0 0 auto;
.content {
margin: 0;
}
#cookie-toggle {
}
}
}
}
var cookieTL;
var topPiecesTL;
var bottomPiecesTL;
var cookieIcon = document.getElementById('cookie-icon');
var cookieModule = document.getElementById('cookies-module');
var toggle = document.getElementById('cookie-toggle');
var toggleTrack = document.getElementById('track');
var toggleStatus = document.getElementById('cookie-status');
var toggleState = true;
var cookiesModuleVisible = true;
function initCookieAnimation() {
TweenLite.defaultEase = Quad.easeOut;
topPiecesTL = new TimelineMax({
paused: false
});
topPiecesTL.timeScale(1);
topPiecesTL
.to('#top-pieces polygon:nth-of-type(1)', 1, {
transformOrigin: "50% 50%",
rotation: "2deg",
y: -1,
x: 5
}, "0")
.to('#top-pieces polygon:nth-of-type(2)', 1, {
transformOrigin: "50% 50%",
rotation: "4deg",
y: -4,
x: 4
}, "0")
.to('#top-pieces polygon:nth-of-type(3)', 1, {
transformOrigin: "50% 50%",
rotation: "2deg",
y: 0,
x: 1
}, "0")
.to('#top-pieces polygon:nth-of-type(4)', 1, {
transformOrigin: "50% 50%",
y: -2,
x: 0
}, "0")
.to('#top-pieces polygon:nth-of-type(5)', 1, {
transformOrigin: "50% 50%",
y: -2,
x: -1
}, "0")
.to('#top-pieces polygon:nth-of-type(6)', 1, {
transformOrigin: "50% 50%",
rotation: "4deg",
y: -5,
x: 1
}, "0")
.to('#top-pieces polygon:nth-of-type(7)', 1, {
transformOrigin: "50% 50%",
y: -1,
x: -1
}, "0");
bottomPiecesTL = new TimelineMax({
paused: false
});
bottomPiecesTL.timeScale(1);
bottomPiecesTL
.to('#bottom-pieces polygon:nth-of-type(1)', 1, {
transformOrigin: "50% 50%",
rotation: "2deg",
y: 3,
x: 2
}, "0")
.to('#bottom-pieces polygon:nth-of-type(2)', 1, {
transformOrigin: "50% 50%",
rotation: "4deg",
y: 4,
x: 4
}, "0")
.to('#bottom-pieces polygon:nth-of-type(3)', 1, {
transformOrigin: "50% 50%",
rotation: "2deg",
y: 4,
x: 5
}, "0")
.to('#bottom-pieces polygon:nth-of-type(4)', 1, {
transformOrigin: "50% 50%",
y: 5,
x: 3
}, "0")
.to('#bottom-pieces polygon:nth-of-type(5)', 1, {
transformOrigin: "50% 50%",
y: 4,
x: 2
}, "0")
.to('#bottom-pieces polygon:nth-of-type(6)', 1, {
transformOrigin: "50% 50%",
rotation: "4deg",
y: 5,
x: 1
}, "0")
.to('#bottom-pieces polygon:nth-of-type(7)', 1, {
transformOrigin: "50% 50%",
y: -1,
x: -1
}, "0");
cookieTL = new TimelineMax({
paused: true,
delay: 0,
repeat: 0,
repeatDelay: 1,
yoyo: false
});
cookieTL
.to('#plate', 1, {
x: -50,
ease: Quad.easeInOut
}, "0")
.to('#cookie-svg', 1, {
transformOrigin: "50% 50%",
rotation: "360deg",
ease: Quad.easeInOut
}, "0")
.to('#bottom-wedge', 1, {
y: 4,
rotation: "4deg",
transformOrigin: "50% 50%",
ease: Quad.easeInOut
}, "0")
.to('#top-wedge', 1, {
y: -5,
rotation: "-5deg",
transformOrigin: "50% 50%",
ease: Quad.easeInOut
}, "0")
.to('#right-wedge', 1, {
x: 5,
y: 1,
rotation: "2deg",
transformOrigin: "50% 50%",
ease: Quad.easeInOut
}, "0")
.to('#middle-crumb', 1, {
transformOrigin: "50% 50%",
rotation: "2deg",
x: 3,
y: 4,
ease: Quad.easeInOut
}, "0")
.add(topPiecesTL, "0")
.add(bottomPiecesTL, "0")
.to('#bottom-wedge', 1, {
scaleX: .7,
scaleY: .7,
opacity: 1,
ease: Quad.easeInOut
}, "0")
.to('#top-wedge', 1, {
scaleX: .7,
scaleY: .7,
opacity: 1,
ease: Quad.easeInOut
}, "0")
.to('#right-wedge', 1, {
scaleX: .7,
scaleY: .7,
opacity: 1,
ease: Quad.easeInOut
}, "0");
//cookieTL.play();
cookieTL.timeScale(1.5);
toggle.addEventListener('click', onToggle);
cookieIcon.addEventListener('click', onCookieIconClick);
}
function onCookieIconClick(e) {
e.preventDefault();
if (cookiesModuleVisible) { // visible currently, so hide
TweenMax.to(cookieModule, 1, {
height: 0,
ease: Quad.easeInOut
});
cookiesModuleVisible = false;
} else { // hidden currently, so show
TweenMax.set(cookieModule, {
height: "auto"
});
TweenMax.from(cookieModule, 1, {
height: 0,
ease: Quad.easeInOut
});
cookiesModuleVisible = true;
}
cookieIcon.classList.toggle('active');
}
function onToggle() {
if (toggleState) { // on currently, turn off
cookieTL.play();
cookieModule.classList.toggle('off');
//toggle.classList.toggle('off');
//toggleStatus.classList.toggle('off');
toggleStatus.innerHTML = "OFF";
toggleState = false;
} else { // off currently, turn on
cookieTL.reverse();
cookieModule.classList.toggle('off');
//toggle.classList.toggle('off');
//toggleStatus.classList.toggle('off');
toggleStatus.innerHTML = "ON";
toggleState = true;
}
}
initCookieAnimation();
Also see: Tab Triggers