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="fake-content prev-section">
<h1>Scroll Me</h1>
<div href="" class="next scroll-down">
<svg class="spinner" width="50px" height="50px" viewBox="0 0 66 66" xmlns="http://www.w3.org/2000/svg">
<circle class="path" fill="none" stroke-width="1" stroke-linecap="round" cx="33" cy="33" r="30"></circle>
</svg>
<svg class="spinner-arrow" xmlns="http://www.w3.org/2000/svg" width="12" height="18" viewBox="0 0 12 18">
<path fill="#000000" fill-rule="evenodd" d="M4.52045455,17.1819 C5.33863636,18.0000818 6.48409091,18.0000818 7.30227273,17.1819 L11.6386364,12.8455364 C11.8840909,12.6000818 11.8840909,12.1909909 11.6386364,11.9455364 C11.3931818,11.7000818 10.9840909,11.7000818 10.7386364,11.9455364 L6.56590909,16.1182636 L6.56590909,0.654627273 C6.56590909,0.245536364 6.32045455,8.18181818e-05 5.91136364,8.18181818e-05 C5.50227273,8.18181818e-05 5.25681818,0.409172727 5.25681818,0.654627273 L5.25681818,16.0364455 L1.16590909,11.9455364 C1.08409091,11.7819 0.838636364,11.7819 0.675,11.7819 C0.511363636,11.7819 0.265909091,11.8637182 0.184090909,11.9455364 C-0.0613636364,12.1909909 -0.0613636364,12.6000818 0.184090909,12.8455364 L4.52045455,17.1819 Z"></path>
</svg>
</div>
</div>
<div class="animation-wrapper" id="animatedSection">
<section class="grid grid-no-gutter section-animate">
<div class="block-left">
<div class="image-wrapper background-image">
<div class="image-content object-fit-image">
<img src="https://twistedsifter.files.wordpress.com/2017/11/022_prod-yourshot-1612162-11117045.jpg" />
</div>
<div class="image-content object-fit-image" >
<img src="https://twistedsifter.files.wordpress.com/2017/11/prod-yourshot-1609181-3_018.jpg" />
</div>
<div class="image-content object-fit-image">
<img src="https://kids.nationalgeographic.com/content/dam/kids/photos/Countries/Q-Z/thailand-rice-field-chaingmai.ngsversion.1396531804152.jpg" />
</div>
</div>
<div class="text-wrapper">
<h4>
Subtitle Slide 1
</h4>
<h4>
Subtitle Slide 2
</h4>
<h4>
Subtitle Slide 3
</h4>
</div>
</div>
<div class="block-middle">
<div class="steps-wrapper">
<div class="step-1"></div>
<div class="step-2"></div>
<div class="step-3"></div>
</div>
<h2>
Slide 1
</h2>
<h2>
Slide 2
</h2>
<h2>
Slide 3
</h2>
</div>
<div class=" block-right">
<div class="text-wrapper">
<div class="text-description">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sed dolor sit amet nisi cursus ullamcorper. Etiam ac metus nisi. Quisque auctor purus magna, ut imperdiet sem hendrerit in.</p>
<a href="/our-offer/support" class="link-click">CTA 1</a>
</div>
<div class="text-description">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sed dolor sit amet nisi cursus ullamcorper. Etiam ac metus nisi. Quisque auctor purus magna, ut imperdiet sem hendrerit in.</p>
<a href="/by-your-side/customer-relationship" class="link-click">CTA 2</a>
</div>
<div class="text-description">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sed dolor sit amet nisi cursus ullamcorper. Etiam ac metus nisi. Quisque auctor purus magna, ut imperdiet sem hendrerit in.</p>
<a href="/by-your-side/co-conception" class="link-click">CTA 3</a>
</div>
</div>
<div class="image-wrapper">
<div class="image-content object-fit-image">
<img src="https://mustseeplaces.eu/wp-content/uploads/2017/09/canada-nat-geo.jpg" />
</div>
<div class="image-content object-fit-image">
<img src="https://twistedsifter.files.wordpress.com/2017/09/prod-yourshot-1352010-10885652_014.jpg" />
</div>
<div class="image-content object-fit-image">
<img src="https://www.tubefilter.com/wp-content/uploads/2016/05/wild-life-nat-geo.jpg" />
</div>
</div>
</div>
</section>
</div>
<div class="fake-content next-section">
<h1>Scroll Me</h1>
<div href="" class="next scroll-up">
<svg class="spinner" width="50px" height="50px" viewBox="0 0 66 66" xmlns="http://www.w3.org/2000/svg">
<circle class="path" fill="none" stroke-width="1" stroke-linecap="round" cx="33" cy="33" r="30"></circle>
</svg>
<svg class="spinner-arrow" xmlns="http://www.w3.org/2000/svg" width="12" height="18" viewBox="0 0 12 18">
<path fill="#000000" fill-rule="evenodd" d="M4.52045455,17.1819 C5.33863636,18.0000818 6.48409091,18.0000818 7.30227273,17.1819 L11.6386364,12.8455364 C11.8840909,12.6000818 11.8840909,12.1909909 11.6386364,11.9455364 C11.3931818,11.7000818 10.9840909,11.7000818 10.7386364,11.9455364 L6.56590909,16.1182636 L6.56590909,0.654627273 C6.56590909,0.245536364 6.32045455,8.18181818e-05 5.91136364,8.18181818e-05 C5.50227273,8.18181818e-05 5.25681818,0.409172727 5.25681818,0.654627273 L5.25681818,16.0364455 L1.16590909,11.9455364 C1.08409091,11.7819 0.838636364,11.7819 0.675,11.7819 C0.511363636,11.7819 0.265909091,11.8637182 0.184090909,11.9455364 C-0.0613636364,12.1909909 -0.0613636364,12.6000818 0.184090909,12.8455364 L4.52045455,17.1819 Z"></path>
</svg>
</div>
</div>
.fake-content {
align-items: center;
background: lightblue;
display: flex;
justify-content: center;
min-height: 100vh;
position: relative;
z-index: 10;
}
.animation-wrapper {
position: relative;
width: 100%;
}
.section-animate {
display: flex;
height: 100vh;
overflow: hidden;
&:not(:first-child) {
display: none;
}
.block-left, .block-right {
flex-basis: 50%;
max-width: 50%;
width: 50%;
}
.block-left {
align-items: flex-end;
display: flex;
overfow: hidden;
z-index: 2;
.background-image {
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
z-index: -1;
img {
height: 100%;
max-width: 100%;
object-fit: cover;
width: 100%;
}
}
.text-wrapper {
left: 20%;
margin-bottom: 20%;
position: relative;
z-index: 10;
&:before {
background: rgba(black, 0.5);
bottom: -200px;
content: '';
display: block;
left: -2rem;
height: 250px;
position: absolute;
width: 1px;
}
}
h4 {
color: white;
line-height: 1.41;
position: absolute;
width: 250px;
&:before {
background: white;
content: '';
display: block;
height: 100%;
left: -2rem;
position: absolute;
width: 1px;
}
}
}
.block-middle {
$block-size: 280px;
background: lightblue;
height: $block-size;
left: 50%;
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
width: $block-size;
z-index: 10;
h2 {
position: absolute;
text-align: center;
top: calc(50% - 20px);
width: 100%;
}
.steps-wrapper {
display: flex;
justify-content: space-between;
left: 50%;
margin: auto;
position: absolute;
top: 60%;
transform: translateX(-50%);
width: 60%;
[class*='step'] {
background: black;
height: 2px;
width: 33px;
}
}
}
.block-right {
background: white;
position: relative;
z-index: 5;
.text-wrapper {
display: flex;
justify-content: center;
}
.text-description{
left: 50%;
margin: auto;
position: absolute;
top: 20%;
transform: translatex(-50%);
width: 50%;
a {
color: blue;
display: inline-block;
margin-top: 2rem;
}
}
.text-wrapper, .image-wrapper {
height: 50vh;
position: relative;
}
.image-wrapper {
overflow: hidden;
}
}
.image-content {
background: black;
height: 100%;
overflow: hidden;
position: absolute;
width: 100%;
z-index: 2;
&:nth-child(2) {
z-index: 3;
}
&:nth-child(3) {
z-index: 4;
}
img{
height: 100%;
max-width: inherit;
object-fit: cover;
position: absolute;
width: inherit;
}
}
}
///Spinner
// Here is where the magic happens
.next-section {
.next {
transform: rotate(180deg);
}
}
.next {
position: relative;
margin-left: 20px;
}
$offset: 245;
$duration: 3s;
.spinner {
animation: rotator $duration linear infinite;
}
.spinner-arrow {
animation: vertical-translate $duration ease-out infinite;
position: absolute;
margin-top: -12px;
left: 19px;
}
@keyframes rotator {
0% { transform: rotate(0deg); }
100% { transform: rotate(250deg); }
}
.path {
stroke-dasharray: $offset;
stroke-dashoffset: 0;
transform-origin: center;
stroke: #000000;
animation: dash $duration linear infinite;
}
@keyframes dash {
0% { stroke-dashoffset: $offset; }
70% {
stroke-dashoffset: $offset/4;
transform:rotate(205deg);
}
100% {
stroke-dashoffset: $offset;
transform:rotate(540deg);
}
}
@keyframes vertical-translate {
0% {opacity:0; top: -20%; }
25% {opacity:1; top: 50%; }
75% {opacity:1; top: 50%; }
100% {opacity:0; top: 120%; }
}
jQuery(function () {
var isMobile = false;
if (window.innerWidth < 1280) {
isMobile = true;
}
if(!isMobile) {
if (jQuery('#animatedSection').length) {
var wrapper = jQuery(".animation-wrapper");
var slides = jQuery(".section-animate");
var firstSlide = slides[0];
var slidesCount = slides.length;
animationSection();
}
}
});
function animationSection() {
var blockLeft = jQuery('.block-left');
var blockLeftImages = jQuery('.block-left > .image-wrapper');
var blockLeftImageContent1 = jQuery('.image-content:nth-child(1)', blockLeftImages);
var blockLeftImageContent2 = jQuery('.image-content:nth-child(2)', blockLeftImages);
var blockLeftImageContent3 = jQuery('.image-content:nth-child(3)', blockLeftImages);
var blockLeftImage1 = jQuery('img', blockLeftImageContent1);
var blockLeftImage2 = jQuery('img', blockLeftImageContent2);
var blockLeftImage3 = jQuery('img', blockLeftImageContent3);
var blockLeftTexts = jQuery('.block-left .text-wrapper');
var blockLeftText1 = jQuery('h4:nth-child(1)', blockLeftTexts);
var blockLeftText2 = jQuery('h4:nth-child(2)', blockLeftTexts);
var blockLeftText3 = jQuery('h4:nth-child(3)', blockLeftTexts);
var blockRight = jQuery('.block-right');
var blockRightImages = jQuery('.block-right > .image-wrapper');
var blockRightImageContent1 = jQuery('.image-content:nth-child(1)', blockRightImages);
var blockRightImageContent2 = jQuery('.image-content:nth-child(2)', blockRightImages);
var blockRightImageContent3 = jQuery('.image-content:nth-child(3)', blockRightImages);
var blockRightImage1 = jQuery('img', blockRightImageContent1);
var blockRightImage2 = jQuery('img', blockRightImageContent2);
var blockRightImage3 = jQuery('img', blockRightImageContent3);
var blockRightTexts = jQuery('.block-right .text-wrapper');
var blockRightText1 = jQuery('.text-description:nth-child(1)', blockRightTexts);
var blockRightText2 = jQuery('.text-description:nth-child(2)', blockRightTexts);
var blockRightText3 = jQuery('.text-description:nth-child(3)', blockRightTexts);
var blockMiddle = jQuery('.block-middle');
var blockMiddleText1 = jQuery('h2:nth-child(2)', blockMiddle);
var blockMiddleText2 = jQuery('h2:nth-child(3)', blockMiddle);
var blockMiddleText3 = jQuery('h2:nth-child(4)', blockMiddle);
var blockMiddleLine1 = jQuery('.steps-wrapper .step-1', blockMiddle);
var blockMiddleLine2 = jQuery('.steps-wrapper .step-2', blockMiddle);
var blockMiddleLine3 = jQuery('.steps-wrapper .step-3', blockMiddle);
// init controller
var controller = new ScrollMagic.Controller();
//-----Animate blockmiddle-----///
TweenMax.to(blockMiddle, 0, {y: '0%'})
var blockMiddleEnter = new ScrollMagic.Scene({
duration: 400,
offset: 0,
triggerHook: "onCenter",
triggerElement: '#animatedSection'
})
.setTween(blockMiddle, { y: '-50%' })
.addTo(controller); // assign the scene to the controller
var blockMiddleLeave = new ScrollMagic.Scene({
duration: 400,
offset: 0,
triggerHook: "onEnter",
triggerElement: '.next-section'
})
.setTween(blockMiddle, { y: '-100%' })
.addTo(controller); // assign the scene to the controller
///INIT: Hide every element except first div
TweenMax.to(jQuery('.image-content:nth-child(n+2)', blockLeftImages), 0, {
x:'0%',
y:'-100%',
})
TweenMax.to(jQuery('h4:nth-child(n+2)', blockLeftTexts), 0, {
autoAlpha: 0,
display:'none',
})
TweenMax.to(jQuery('h2:not(:nth-child(2))', blockMiddle), 0, {
autoAlpha: 0,
display:'none',
y: '-20px'
})
TweenMax.to(jQuery('.image-content:nth-child(n+2)', blockRightImages), 0, {
x:'-100%',
y:'0%',
})
TweenMax.to(jQuery('.text-description:nth-child(n+2)', blockRightTexts), 0, {
autoAlpha: 0,
display:'none'
})
TweenMax.to(jQuery(blockMiddleLine1), 0, {
backgroundColor:"#ffffff",
})
TweenMax.to(jQuery(blockLeftImage1), 0, {
y: '-30%'
})
TweenMax.to(jQuery(blockLeftImage2), 0, {
y: '90%'
})
TweenMax.to(jQuery(blockLeftImage3), 0, {
y: '90%'
})
TweenMax.to(jQuery(blockRightImage1), 0, {
y: '-30%'
})
TweenMax.to(jQuery(blockRightImage2), 0, {
x: '90%'
})
TweenMax.to(jQuery(blockRightImage3), 0, {
x: '90%'
})
var leftImageEnter = new ScrollMagic.Scene({
duration: 800,
offset: 0,
triggerHook: "onLeave",
triggerElement: '.prev-section'
})
.setTween(blockLeftImage1, { y: '0%' })
.addTo(controller); // assign the scene to the controller
var rightImageEnter = new ScrollMagic.Scene({
duration: 600,
offset: 400,
triggerHook: "onLeave",
triggerElement: '.prev-section'
})
.setTween(blockRightImage1, { y: '0%' })
.addTo(controller); // assign the scene to the controller
/* LEFT ANIMATION */
///Manage left image animation
var tweenLeftImage = new TimelineMax()
/*Step 1*/
tweenLeftImage.to(blockLeftImageContent1, 10, {x:'0%', y:'100%'}, '+=5');
tweenLeftImage.to(blockLeftImage1, 10, {x:'0%', y:'-90%'}, '-=10');
tweenLeftImage.to(blockLeftImageContent2, 10, {x:'0%', y:'0%'}, '-=10'),
tweenLeftImage.to(blockLeftImage2, 10, {x:'0%', y:'0%'}, '-=10');
tweenLeftImage.to(blockLeftImageContent3, 10, {x:'0%', y:'0%'}, '+=5'),
tweenLeftImage.to(blockLeftImage3, 10, {x:'0%', y:'0%'}, '-=10');
tweenLeftImage.to(blockLeftImage2, 10, {x:'0%', y:'10%'}, '-=10');
///Manage left text animation
var tweenLeftText = new TimelineMax()
/*Step 1*/
tweenLeftText.to(blockLeftText2, 10, { autoAlpha: 1, display:'block'}, '+=5'),
tweenLeftText.to(blockLeftText1, 10, { autoAlpha: 0, display:'none'}, '-=10');
/*Step 2*/
tweenLeftText.to(blockLeftText3, 10, { autoAlpha: 1, display:'block'}, '+=5'),
tweenLeftText.to(blockLeftText2, 10, { autoAlpha: 0, display:'none'}, '-=10');
/* RIGHT ANIMATION */
var tweenRightImage = new TimelineMax()
tweenRightImage.to(blockRightImageContent1, 10, {x:'100%', y:'0%'}, '+=5');
tweenRightImage.to(blockRightImage1, 10, {x:'-90%', y:'0%'}, '-=10');
tweenRightImage.to(blockRightImageContent2, 10, {x:'0%', y:'0%'}, '-=10'),
tweenRightImage.to(blockRightImage2, 10, {x:'0%', y:'0%'}, '-=10');
tweenRightImage.to(blockRightImageContent3, 10, {x:'0%', y:'0%'}, '+=5'),
tweenRightImage.to(blockRightImage3, 10, {x:'0%', y:'0%'}, '-=10');
tweenRightImage.to(blockRightImage2, 10, {x:'10%', y:'0%'}, '-=10');
///End right image animation
///Manage right text animation
var tweenRightText = new TimelineMax()
/*Step 1*/
tweenRightText.to(blockRightText2, 10, { autoAlpha: 1, display:'block'}, '+=5'),
tweenRightText.to(blockRightText1, 10, { autoAlpha: 0, display:'none'}, '-=10');
/*Step 2*/
tweenRightText.to(blockRightText3, 10, { autoAlpha: 1, display:'block'}, '+=5'),
tweenRightText.to(blockRightText2, 10, { autoAlpha: 0, display:'none'}, '-=10');
///End right text animation
/* MIDDLE ANIMATION */
///Manage middle text animation
var tweenMiddle = new TimelineMax()
tweenMiddle.to(blockMiddleText2, 10, { autoAlpha: 1, display:'block', y: 0}, '+=5'),
tweenMiddle.to(blockMiddleLine2, 10, { backgroundColor: '#ffffff'}, '-=10');
tweenMiddle.to(blockMiddleText1, 10, { autoAlpha: 0, display:'none', y: 0}, '-=10');
tweenMiddle.to(blockMiddleLine1, 10, { backgroundColor: '#7f886c'}, '-=10');
tweenMiddle.to(blockMiddleText3, 10, { autoAlpha: 1, display:'block', y: 0}, '+=5'),
tweenMiddle.to(blockMiddleLine3, 10, { backgroundColor: '#ffffff'}, '-=10');
tweenMiddle.to(blockMiddleText2, 10, { autoAlpha: 0, display:'none', y: 0}, '-=10');
tweenMiddle.to(blockMiddleLine2, 10, { backgroundColor: '#7f886c'}, '-=10');
tweenMiddle.to(blockMiddle, 10, { y: '-50%' }, '+=5')
// create tween
var timeline = new TimelineMax()
.add(tweenLeftImage, 0)
.add(tweenLeftText, 0)
.add(tweenRightImage, 0)
.add(tweenRightText, 0)
.add(tweenMiddle, 0)
timeline.timeScale(0.1)
new ScrollMagic.Scene({
duration: '100%',
triggerHook: 'onLeave',
triggerElement: '#animatedSection',
})
.setPin('#animatedSection')
.setTween(timeline)
.addTo(controller); // assign the scene to the controller
//----Smooth scroll IE to prevent animation issue ----//
jQuery.fn.wheel = function (callback) {
return this.each(function () {
jQuery(this).on('mousewheel DOMMouseScroll', function (e) {
e.delta = null;
if (e.originalEvent) {
if (e.originalEvent.wheelDelta) e.delta = e.originalEvent.wheelDelta / -40;
if (e.originalEvent.deltaY) e.delta = e.originalEvent.deltaY;
if (e.originalEvent.detail) e.delta = e.originalEvent.detail;
}
if (typeof callback == 'function') {
callback.call(this, e);
}
});
});
};
if(navigator.userAgent.match(/Trident\/7\./)) {
jQuery('body').wheel(function (e) {
e.preventDefault();
var wheelDelta = e.delta * -30;
var currentScrollPosition = window.pageYOffset;
window.scrollTo(0, currentScrollPosition - wheelDelta);
});
}
};
Also see: Tab Triggers