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.
<section>
<h3>algo</h3>
<p>
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Soluta reiciendis non explicabo, accusamus debitis deleniti unde inventore nam aliquam corporis tempora, libero necessitatibus optio iure quis ipsa, nostrum itaque quam.
</p>
</section>
<article class="panelContainer">
<div id='pnl2012' class='panel'>
<h3>2012</h3>
</div>
<div id='pnl2013' class='panel'>
<h3>2013</h3>
</div>
<div id='pnl2014' class='panel'>
<h3>2014</h3>
</div>
<div id='pnl2015' class='panel'>
<h3>2015</h3>
</div>
<div id='pnl2016' class='panel'>
<h3>2016</h3>
</div>
<div id='pnl2017' class='panel'>
<h3>2017</h3>
</div>
<div id='pnl2018' class='panel'>
<h3>2018</h3></div>
<div id='pnl2019' class='panel'>
<h3>2019</h3>
</div>
<div id='pnl2020' class='panel'>
<h3>2020</h3>
</div>
<div id='pnl2021' class='panel'>
<h3>2021</h3>
</div>
<div class="timeline">
<div class="yearLineContainer">
<div class="lineCenter"></div>
<span id='id2012' class="yearLine" >2012</span>
<span id='id2013' class="yearLine" >2013</span>
<span id='id2014' class="yearLine" >2014</span>
<span id='id2015' class="yearLine" >2015</span>
<span id='id2016' class="yearLine" >2016</span>
<span id='id2017' class="yearLine" >2017</span>
<span id='id2018' class="yearLine" >2018</span>
<span id='id2019' class="yearLine" >2019</span>
<span id='id2020' class="yearLine" >2020</span>
<span id='id2021' class="yearLine" >2021</span>
</div>
</div>
</article>
<h3>algo</h3>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Sit facere nam eos a ab fugit exercitationem vitae? Inventore veritatis dicta quisquam deserunt, quia fugiat magni nesciunt ipsum tempore sint, velit, dolore saepe nulla sunt hic. Natus eum laboriosam fugit non odit atque quod voluptate rerum, beatae voluptatem sunt necessitatibus similique dolorem ullam exercitationem dolorum aliquid accusamus eius, consectetur cumque minima et porro. Suscipit ullam a quidem assumenda veritatis enim unde tempora, mollitia expedita quasi aut cumque ducimus quis sit velit maxime? Tempore labore ea nisi laudantium deleniti in eligendi non. Pariatur ducimus quibusdam alias suscipit eius, vitae at eligendi, animi odio voluptatibus sed, nisi distinctio necessitatibus. Vero, quod enim dolorum unde illum minus pariatur aspernatur sint, voluptates maxime aliquid et assumenda quidem earum debitis voluptatum consequuntur sunt quos voluptatem. Maiores exercitationem officia eligendi hic dicta vel, modi fugit ad perferendis incidunt voluptas accusamus neque. Accusamus vel deleniti fugit libero, quos quae cumque ipsa ipsam, ratione, accusantium unde nostrum quasi deserunt enim. Porro, eius temporibus eos mollitia deleniti exercitationem praesentium et dolorum corporis itaque. Ab incidunt eveniet eius corporis blanditiis, tenetur est dicta libero dignissimos consectetur perspiciatis quam, molestiae voluptatibus ut quaerat saepe a. Quidem laborum nemo, odio tempora blanditiis aliquid quibusdam possimus dolore amet quae eligendi corrupti iusto distinctio provident nam quaerat quisquam dolorum officia facere obcaecati tenetur. Voluptatibus voluptatum nulla doloribus ratione adipisci ipsam sequi, placeat quos, aperiam quia consequuntur odit natus ex unde temporibus, asperiores et? Officia similique nam delectus cumque voluptate, omnis a dolor repellat totam? Saepe, ex, sequi explicabo repellendus ab quidem magni veritatis facere, laudantium dolores eaque. Numquam labore necessitatibus fuga voluptates assumenda! Beatae aliquam nobis quae amet debitis suscipit sapiente odit totam vel autem, facilis delectus, impedit minus error! Voluptates in tempore est ab dolor illo eos, pariatur expedita ad, recusandae amet quibusdam aut iste quae atque? Maxime voluptas, delectus sapiente itaque at id nobis mollitia, cum rem blanditiis temporibus atque, quae voluptatum consequuntur! Eius dicta, tempore nihil assumenda aperiam accusantium nobis earum? Quo voluptatum excepturi quidem laboriosam repudiandae, exercitationem odit at, fuga neque qui laborum quis iste ex nulla nisi nobis tempore vel sapiente incidunt recusandae? Esse assumenda sunt, aut harum alias suscipit debitis soluta libero, quod omnis totam animi odio aperiam numquam nam, maxime voluptate tenetur qui sed? Voluptate molestiae unde atque veniam corporis laborum? Adipisci, labore. Laborum quibusdam corporis iusto rem eius cupiditate, cumque necessitatibus, in omnis veniam, temporibus tempora recusandae consequuntur autem? Vitae consequuntur iure optio voluptatem facilis, atque est nostrum quod. Veniam incidunt nobis ut vero voluptatum iusto aliquid? Soluta quisquam et nam ad repellendus incidunt, iure odit laudantium recusandae officia, ullam delectus est eligendi cum? Aspernatur, praesentium. Alias beatae ipsum unde. Quod quasi ipsa fuga fugiat soluta nostrum cum voluptatum necessitatibus id aspernatur est corrupti expedita sunt facere tempore, suscipit aperiam provident nesciunt optio enim tenetur ex dicta. Consectetur necessitatibus cumque sequi rem consequatur perspiciatis vitae, sint voluptatibus nemo architecto veniam dolorem possimus minus non nesciunt, molestias placeat beatae officia sit? Odit sit necessitatibus consectetur deserunt nam labore!
</p>
* {
margin: 0;
overflow-x: hidden;
}
.panelContainer {
width: 100vw;
height: 100vh;
margin: 0 auto;
background-color: rgb(99, 76, 76);
display: flex;
align-items: center;
overflow: hidden;
}
.panel {
box-sizing: border-box;
min-width: 100vw;
height: 100vh;
background-color: rgb(108, 148, 114);
border-left: solid 3px #ffffff;
color: white;
display: flex;
align-items: center;
justify-content: center;
z-index: 10;
}
/* === === ===TimeLine=== === === */
.timeline {
border: solid 1px;
display: flex;
height: 50px;
justify-content: center;
background-color: rgb(50, 61, 85);
position: fixed;
bottom: 0;
width: 100%;
z-index: 100;
}
.yearLineContainer {
width: 90%;
display: flex;
justify-content: space-between;
align-items: center;
position: relative;
background-color: rgb(50, 61, 85);
overflow-x: auto;
}
.yearLine {
transform: rotate(90deg);
border-bottom: solid 2px;
height: 20px;
color: #fff;
font-weight: bolder;
background-color: rgb(50, 61, 85);
}
.lineCenter {
width: 100%;
height: 2px;
position: absolute;
background-color: rgb(255, 255, 255);
}
gsap.registerPlugin(ScrollTrigger);
let sections = gsap.utils.toArray(".panel");
let numOfPanels = sections.length;
let lengthPanel = document.querySelector(".panel").offsetWidth;
if (window.innerWidth > 800) {
lengthPanel = window.innerWidth;
}
let lengthAllPanels = lengthPanel * numOfPanels;
let scrollTween = gsap.to(sections, {
scrollTrigger: {
trigger: ".panelContainer",
start: "bottom bottom",
end: lengthAllPanels - lengthPanel,
pin: true,
scrub: true,
snap: directionalSnap(1 / (numOfPanels - 1)),
},
x: -lengthAllPanels + lengthPanel,
ease: "none",
});
function directionalSnap(increment) {
let snapFunc = gsap.utils.snap(increment);
return (raw, self) => {
let n = snapFunc(raw);
return Math.abs(n - raw) < 1e-4 || n < raw === self.direction < 0
? n
: self.direction < 0
? n - increment
: n + increment;
};
}
idLinesTimeLine = [
"2012",
"2013",
"2014",
"2015",
"2016",
"2017",
"2018",
"2019",
"2020",
"2021",
];
idLinesTimeLine.forEach((year, i) => {
gsap.to(`#id${year}`, {
scrollTrigger: {
trigger: `#pnl${year}`,
containerAnimation: scrollTween,
start: "center 55%",
end: "center 45%",
toggleActions: "play reset restart reset",
},
color: "yellow",
});
});
//! ======CLICK BUG==========
let id2012 = document.getElementById("id2012");
let id2013 = document.getElementById("id2013");
let id2014 = document.getElementById("id2014");
let id2015 = document.getElementById("id2015");
let id2016 = document.getElementById("id2016");
let id2017 = document.getElementById("id2017");
let id2018 = document.getElementById("id2018");
let id2019 = document.getElementById("id2019");
let id2020 = document.getElementById("id2020");
let id2021 = document.getElementById("id2021");
id2012.addEventListener("click", () => goTo(0));
id2013.addEventListener("click", () => goTo(1));
id2014.addEventListener("click", () => goTo(2));
id2015.addEventListener("click", () => goTo(3));
id2016.addEventListener("click", () => goTo(4));
id2017.addEventListener("click", () => goTo(5));
id2018.addEventListener("click", () => goTo(6));
id2019.addEventListener("click", () => goTo(7));
id2020.addEventListener("click", () => goTo(8));
id2021.addEventListener("click", () => goTo(9));
function goTo(index) {
console.log("goTo", index);
let start = scrollTween.scrollTrigger.start,
end = scrollTween.scrollTrigger.end,
progress = index / (sections.length - 1);
gsap.to(window, {
scrollTo: start + (end - start) * progress
});
}
Also see: Tab Triggers