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 class="wrapper">
<div class="scroll-indicator">
<!--clock-->
<div class="clock">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 166.719 166.72">
<rect id="rect-outer" x="0" y="0" width="166" height="166" />
<rect id="rect-inner" x="5" y="5" width="156" height="156" />
<path id="face-outer" d="M83.359 166.72C37.395 166.72 0 129.325 0 83.36S37.395 0 83.359 0s83.359 37.396 83.359 83.36-37.394 83.36-83.359 83.36zm0-165.72C37.946 1 1 37.946 1 83.36c0 45.413 36.946 82.359 82.359 82.359s82.359-36.946 82.359-82.359C165.719 37.946 128.772 1 83.359 1z" opacity="0.3"/>
<path id="face-inner" d="M83.359 162.083c-43.408 0-78.723-35.314-78.723-78.723S39.951 4.637 83.359 4.637s78.723 35.315 78.723 78.724-35.314 78.722-78.723 78.722zm0-156.446c-42.856 0-77.723 34.866-77.723 77.724 0 42.856 34.867 77.723 77.723 77.723s77.723-34.866 77.723-77.723c.001-42.858-34.866-77.724-77.723-77.724z"/>
<path id="hour-hand" d="M88.563 110.386c-.031-.014-3.573-1.168-4.518-3.402.583-.344.992-1.108.992-2 0-.865-.385-1.606-.94-1.965.662-.905 1.755-5.739 1.755-7.972 0-1.887-.774-2.917-1.444-3.457a2.307 2.307 0 0 0 1.268-2.055c0-.588-.226-1.119-.587-1.527a4.784 4.784 0 0 0 3.05-4.45 4.785 4.785 0 0 0-4.779-4.779 4.784 4.784 0 0 0-4.778 4.779 4.784 4.784 0 0 0 3.05 4.45 2.296 2.296 0 0 0-.587 1.527c0 .9.519 1.671 1.268 2.055-.669.54-1.444 1.57-1.444 3.457 0 2.232 1.094 7.066 1.755 7.972-.555.358-.94 1.1-.94 1.965 0 .892.408 1.655.991 2-.946 2.23-4.486 3.389-4.518 3.402a.334.334 0 0 0-.191.377.335.335 0 0 0 .328.266c1.649 0 3.575 3.1 4.06 4.86.545 1.975.668 3.979.672 4.048v.818a.335.335 0 1 0 .67 0v-.818c.004-.068.127-2.073.672-4.048.485-1.761 2.411-4.86 4.06-4.86a.335.335 0 0 0 .135-.643zm-8.305-26.828a3.106 3.106 0 0 1 3.102-3.103c1.711 0 3.103 1.392 3.103 3.103s-1.392 3.102-3.103 3.102a3.105 3.105 0 0 1-3.102-3.102z"/>
<path id="min-hand" d="M84.34 78.656c.004-.034.02-.062.02-.097l-.33-27.77c2.17-.328 3.844-2.188 3.844-4.446 0-.872-.26-1.68-.69-2.37-.008-.016-.006-.033-.016-.048-.017-.023-.032-.05-.05-.074-.011-.017-.021-.034-.033-.05-2.647-3.913-3.22-14.01-3.225-14.112a.501.501 0 0 0-1 0c-.004.102-.576 10.2-3.225 14.111l-.032.05c-.017.024-.033.052-.05.075-.01.015-.01.032-.017.048a4.465 4.465 0 0 0-.69 2.37c0 2.25 1.66 4.104 3.818 4.442L82.36 78.56c0 .034.016.062.02.097a4.96 4.96 0 0 0-3.976 4.855 4.961 4.961 0 0 0 4.956 4.955 4.96 4.96 0 0 0 4.955-4.955 4.963 4.963 0 0 0-3.975-4.856zm-.98 7.811a2.958 2.958 0 0 1-2.955-2.955 2.958 2.958 0 0 1 2.955-2.955 2.958 2.958 0 0 1 2.956 2.955 2.958 2.958 0 0 1-2.956 2.955z"/>
<g id="clock-markers">
<path id="marker-2" d="M116.169 27.53a1 1 0 0 1-.865-1.5l1.566-2.713a1 1 0 0 1 1.732 1l-1.566 2.713a.996.996 0 0 1-.867.5z"/>
<path id="marker-3" d="M140.19 51.55a1 1 0 0 1-.501-1.866l2.713-1.566a1 1 0 1 1 1 1.732l-2.713 1.566a.992.992 0 0 1-.499.134z"/>
<path id="marker-4" d="M152.113 84.36h-3.133a1 1 0 1 1 0-2h3.133a1 1 0 1 1 0 2z"/>
<path id="marker-5" d="M142.901 118.737a.992.992 0 0 1-.499-.134l-2.714-1.567a1 1 0 1 1 1-1.732l2.714 1.567a1 1 0 0 1-.501 1.866z"/>
<path id="marker-6" d="M117.737 143.902a1 1 0 0 1-.867-.5l-1.566-2.714a1 1 0 0 1 1.732-1l1.566 2.714a1 1 0 0 1-.865 1.5z"/>
<path id="marker-7" d="M83.359 153.113a1 1 0 0 1-1-1v-3.134a1 1 0 1 1 2 0v3.134a1 1 0 0 1-1 1z"/>
<path id="marker-8" d="M48.981 143.903a1 1 0 0 1-.865-1.5l1.566-2.713a1 1 0 1 1 1.732 1l-1.566 2.713a.996.996 0 0 1-.867.5z"/>
<path id="marker-9" d="M23.817 118.737a1 1 0 0 1-.501-1.866l2.714-1.566a1 1 0 0 1 1 1.732l-2.714 1.566a.992.992 0 0 1-.499.134z"/>
<path id="marker-10" d="M17.738 84.36h-3.133a1 1 0 1 1 0-2h3.133a1 1 0 1 1 0 2z"/>
<path id="marker-11" d="M26.528 51.55a.995.995 0 0 1-.499-.134l-2.713-1.566a1 1 0 1 1 1-1.732l2.713 1.566a1 1 0 0 1-.501 1.866z"/>
<path id="marker-12" d="M50.55 27.53a.998.998 0 0 1-.867-.5l-1.566-2.713a1 1 0 0 1 1.732-1l1.566 2.713a1 1 0 0 1-.865 1.5z"/>
<path id="marker-1" d="M83.359 18.739a1 1 0 0 1-1-1v-3.133a1 1 0 1 1 2 0v3.133a1 1 0 0 1-1 1z"/>
</g>
</svg>
</div>
<!--Text-->
<div class="scroll-text">scroll</div>
</div>
<div class="content">
<section>
<h1>Scrolling SVG Clock</h1>
<p>Uses <a href="https://greensock.com/">GSAP</a> to animate the hands depending on the scroll position, which is handled by <a href="http://scrollmagic.io/">ScrollMagic</a>. The text underneath the clock is animated using the <a href="https://greensock.com/docs/#/HTML5/Text/ScrambleTextPlugin/">GSAP ScrambleTextPlugin</a> (premium).</p>
<p>The start/end time can be adjusted by altering start_time.</p>
<p>This was originally created for the <a href="https://bramleyandgage.com/6-oclock/">6 O'Clock Gin</a> website we created at <a href="https://www.craftedbygc.com/">Green Chameleon</a>.</p>
<p>Remaining text too allow page to scroll. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur dolor quos, rerum voluptate repellendus debitis voluptas minus nam ut tenetur. Nisi consequatur dolorum deserunt cum repellat recusandae! Nam, nobis, optio.</p>
</section>
<section>
<h1>Pariatur dolor</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur dolor quos, rerum voluptate repellendus debitis voluptas minus nam ut tenetur. Nisi consequatur dolorum deserunt cum repellat recusandae! Nam, nobis, optio.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur dolor quos, rerum voluptate repellendus debitis voluptas minus nam ut tenetur. Nisi consequatur dolorum deserunt cum repellat recusandae! Nam, nobis, optio.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur dolor quos, rerum voluptate repellendus debitis voluptas minus nam ut tenetur. Nisi consequatur dolorum deserunt cum repellat recusandae! Nam, nobis, optio.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur dolor quos, rerum voluptate repellendus debitis voluptas minus nam ut tenetur. Nisi consequatur dolorum deserunt cum repellat recusandae! Nam, nobis, optio.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur dolor quos, rerum voluptate repellendus debitis voluptas minus nam ut tenetur. Nisi consequatur dolorum deserunt cum repellat recusandae! Nam, nobis, optio.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur dolor quos, rerum voluptate repellendus debitis voluptas minus nam ut tenetur. Nisi consequatur dolorum deserunt cum repellat recusandae! Nam, nobis, optio.</p>
</section>
<section>
<h1>consectetur adipisicing</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur dolor quos, rerum voluptate repellendus debitis voluptas minus nam ut tenetur. Nisi consequatur dolorum deserunt cum repellat recusandae! Nam, nobis, optio.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur dolor quos, rerum voluptate repellendus debitis voluptas minus nam ut tenetur. Nisi consequatur dolorum deserunt cum repellat recusandae! Nam, nobis, optio.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur dolor quos, rerum voluptate repellendus debitis voluptas minus nam ut tenetur. Nisi consequatur dolorum deserunt cum repellat recusandae! Nam, nobis, optio.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur dolor quos, rerum voluptate repellendus debitis voluptas minus nam ut tenetur. Nisi consequatur dolorum deserunt cum repellat recusandae! Nam, nobis, optio.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur dolor quos, rerum voluptate repellendus debitis voluptas minus nam ut tenetur. Nisi consequatur dolorum deserunt cum repellat recusandae! Nam, nobis, optio.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur dolor quos, rerum voluptate repellendus debitis voluptas minus nam ut tenetur. Nisi consequatur dolorum deserunt cum repellat recusandae! Nam, nobis, optio.</p>
</section>
<section>
<h1>dolor sit amet</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur dolor quos, rerum voluptate repellendus debitis voluptas minus nam ut tenetur. Nisi consequatur dolorum deserunt cum repellat recusandae! Nam, nobis, optio.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur dolor quos, rerum voluptate repellendus debitis voluptas minus nam ut tenetur. Nisi consequatur dolorum deserunt cum repellat recusandae! Nam, nobis, optio.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur dolor quos, rerum voluptate repellendus debitis voluptas minus nam ut tenetur. Nisi consequatur dolorum deserunt cum repellat recusandae! Nam, nobis, optio.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur dolor quos, rerum voluptate repellendus debitis voluptas minus nam ut tenetur. Nisi consequatur dolorum deserunt cum repellat recusandae! Nam, nobis, optio.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur dolor quos, rerum voluptate repellendus debitis voluptas minus nam ut tenetur. Nisi consequatur dolorum deserunt cum repellat recusandae! Nam, nobis, optio.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur dolor quos, rerum voluptate repellendus debitis voluptas minus nam ut tenetur. Nisi consequatur dolorum deserunt cum repellat recusandae! Nam, nobis, optio.</p>
</section>
<section>
<h1>Lorem ipsum</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur dolor quos, rerum voluptate repellendus debitis voluptas minus nam ut tenetur. Nisi consequatur dolorum deserunt cum repellat recusandae! Nam, nobis, optio.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur dolor quos, rerum voluptate repellendus debitis voluptas minus nam ut tenetur. Nisi consequatur dolorum deserunt cum repellat recusandae! Nam, nobis, optio.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur dolor quos, rerum voluptate repellendus debitis voluptas minus nam ut tenetur. Nisi consequatur dolorum deserunt cum repellat recusandae! Nam, nobis, optio.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur dolor quos, rerum voluptate repellendus debitis voluptas minus nam ut tenetur. Nisi consequatur dolorum deserunt cum repellat recusandae! Nam, nobis, optio.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur dolor quos, rerum voluptate repellendus debitis voluptas minus nam ut tenetur. Nisi consequatur dolorum deserunt cum repellat recusandae! Nam, nobis, optio.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur dolor quos, rerum voluptate repellendus debitis voluptas minus nam ut tenetur. Nisi consequatur dolorum deserunt cum repellat recusandae! Nam, nobis, optio.</p>
</section>
</div>
</div>
$dark_blue: #100943;
html, body {
margin: 0;
}
html {
background: $dark_blue;
font-family: sans-serif;
}
.wrapper {
position: relative;
width: 75%;
margin: auto;
max-width: 1200px;
padding-left: 300px;
}
/* Scroll Indicator */
.scroll-indicator{
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
position: fixed;
left: 50px;
top: 0;
z-index: 1;
height: 100%;
width: 250px;
text-align: center;
transform: translateZ(0);
svg{
width: 80%;
fill: white;
}
#face-outer,
#face-inner {
fill: none;
stroke: white;
stroke-width: 1px;
}
rect {
display: none;
}
#clock-markers path {
opacity: 0.3;
}
.scroll-text{
margin-top: 25px;
transform-origin: 0% 50%;
transform: translateX(50%) rotate(90deg);
font-size: rem(14px);
text-transform: uppercase;
color: white;
white-space: nowrap;
}
}
/* Content */
.content {
margin: auto;
color: white;
h1 {
font-size: 1.6em;
padding: 2em 0 1em;
text-transform: uppercase;
}
p{
line-height: 1.5;
margin: 1em 0;
}
a {
color: white;
}
}
//* Clock animation
// Start time
const start_time = 3;
const start_degree = ((360 / 12)*start_time)+180; // Calculation is a bit odd as SVG originally pointed to '6'
// Hour hand (360degree rotation)
const hour_hand = '#hour-hand';
const hour_hand_tween = new TimelineMax({ repeat: 0 });
hour_hand_tween.set(hour_hand, { css:{transformOrigin: '50% 11%'} });
hour_hand_tween.set(hour_hand, { rotation: start_degree+'deg' });
hour_hand_tween.to(hour_hand, 12, { rotation: '+=360deg', ease: Power0.easeNone });
// Minute hand - rotate 12 times over course of animation
const min_hand = '#min-hand';
const min_hand_tween = new TimelineMax({ repeat: 11 });
min_hand_tween.set(min_hand, { css:{transformOrigin: '50% 92%'} });
min_hand_tween.to(min_hand, 1, { rotation: '360deg', ease: Power0.easeNone });
// Markers - each marker same duration as one rotation, delayed by 1 so first lights up as reached
function reorder(data, index) {
return data.slice(index).concat(data.slice(0, index));
};
const markers = reorder($('#clock-markers path').toArray(), start_time);
const marker_tween = new TimelineMax({ repeat: 0, delay: 1 });
marker_tween.staggerTo(markers, 1, { opacity: 1, ease: Power0.easeNone }, 1);
// Set up timeline
const clock_tween = new TimelineMax({
repeat: 1,
onRepeat: () => {
TweenMax.to('#face-outer', 1, {morphSVG:'#rect-outer'});
TweenMax.to('#face-inner', 1, {morphSVG:'#rect-inner'});
}
});
clock_tween.add(hour_hand_tween, 0);
clock_tween.add(min_hand_tween, 0);
clock_tween.add(marker_tween, -0.5); // Offset by half of one rotation
// Set up scrollmagic scene
const animateWithScroll = true;
if(animateWithScroll){
const clock_controller = new ScrollMagic.Controller();
const clock_scene = new ScrollMagic.Scene();
clock_scene
.triggerElement('.content')
.triggerHook('onLeave')
.duration( $('.content').height() - $('.scroll-indicator').height() )
.setTween(clock_tween)
.addTo(clock_controller);
}
// Scene duration on resize
window.addEventListener('resize', function(){
clock_scene.duration( $('.content').height() - $('.scroll-indicator').height() );
});
//* Text animation
const text_controller = new ScrollMagic.Controller();
$('section').each(function(i, element){
new ScrollMagic.Scene()
.triggerElement(element)
.triggerHook(0.4)
.addTo(text_controller)
.setTween(
'.scroll-text',
0.75,
{text: $(element).find('h1:first').html(), ease: Power3.easeInOut}
)
});
Also see: Tab Triggers