Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Physic Milestones Timeline - Date 11 (24 days of animation)
<section class="timeline">
<ul>
<li>
<div>
<time>1687</time>
<div class="discovery">
<h1>Discovery</h1>
<p>
Laws of motion
</p>
</div>
<div class="scientist">
<h1>Scientist</h1>
<span>Newton</span>
</div>
</div>
</li>
<li>
<div>
<time>1785</time>
<div class="discovery">
<h1>Discovery</h1>
<p>
Law of electrostatic attraction
</p>
</div>
<div class="scientist">
<h1>Scientist</h1>
<span>Coulomb</span>
</div>
</div>
</li>
<li>
<div>
<time>1827</time>
<div class="discovery">
<h1>Discovery</h1>
<p>
Law of Electric Resistance
</p>
</div>
<div class="scientist">
<h1>Scientist</h1>
<span>G.S Ohm</span>
</div>
</div>
</li>
<li>
<div>
<time>1831</time>
<div class="discovery">
<h1>Discovery</h1>
<p>
Electromagnetic Induction
</p>
</div>
<div class="scientist">
<h1>Scientist</h1>
<span>Michael Faraday</span>
</div>
</div>
</li>
<li>
<div>
<time>1867</time>
<div class="discovery">
<h1>Discovery</h1>
<p>
Dynamite
</p>
</div>
<div class="scientist">
<h1>Scientist</h1>
<span>Alfred Nobel</span>
</div>
</div>
</li>
<li>
<div>
<time>1895</time>
<div class="discovery">
<h1>Discovery</h1>
<p>
X Rays
</p>
</div>
<div class="scientist">
<h1>Scientist</h1>
<span>Roentgen</span>
</div>
</div>
</li>
<li>
<div>
<time>1897</time>
<div class="discovery">
<h1>Discovery</h1>
<p>
Electron
</p>
</div>
<div class="scientist">
<h1>Scientist</h1>
<span>J.J.Thomson</span>
</div>
</div>
</li>
<li>
<div>
<time>1898</time>
<div class="discovery">
<h1>Discovery</h1>
<p>
Radium
</p>
</div>
<div class="scientist">
<h1>Scientist</h1>
<span>Madam Curie</span>
</div>
</div>
</li>
<li>
<div>
<time>1900</time>
<div class="discovery">
<h1>Discovery</h1>
<p>
Quantum Theory
</p>
</div>
<div class="scientist">
<h1>Scientist</h1>
<span>Max Plank</span>
</div>
</div>
</li>
<li>
<div>
<time>1905</time>
<div class="discovery">
<h1>Discovery</h1>
<p>
Principle of Relativity
</p>
</div>
<div class="scientist">
<h1>Scientist</h1>
<span>Albert Einstein</span>
</div>
</div>
</li>
<li>
<div>
<time>1905</time>
<div class="discovery">
<h1>Discovery</h1>
<p>
Photo electric effect
</p>
</div>
<div class="scientist">
<h1>Scientist</h1>
<span>Albert Einstein</span>
</div>
</div>
</li>
<li>
<div>
<time>1942</time>
<div class="discovery">
<h1>Discovery</h1>
<p>
Nuclear Reactor
</p>
</div>
<div class="scientist">
<h1>Scientist</h1>
<span>Anrico Fermi</span>
</div>
</div>
</li>
</ul>
</section>
var items = document.querySelectorAll(".timeline li");
function isElementInViewport(el) {
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
function callbackFunc() {
for (var i = 0; i < items.length; i++) {
if (isElementInViewport(items[i])) {
if(!items[i].classList.contains("in-view")){
items[i].classList.add("in-view");
}
} else if(items[i].classList.contains("in-view")) {
items[i].classList.remove("in-view");
}
}
}
window.addEventListener("load", callbackFunc);
window.addEventListener("scroll", callbackFunc);
$primary-color: #fff;
$background-color: linear-gradient(54deg, #9164ff, #8bfff4);
$text-color: #3c3f64;
*,
*::before,
*::after {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font: normal 16px/1.5 'Titillium Web', sans-serif;
background: $background-color;
color: $text-color;
overflow-x: hidden;
padding-bottom: 50px;
}
// STYLING
.timeline {
ul {
li {
list-style-type: none;
position: relative;
width: 6px;
margin: 0 auto;
padding-top: 50px;
background: #fff;
&::after {
content: '';
position: absolute;
left: 50%;
bottom: 0;
transform: translateX(-50%) rotate(45deg);
width: 20px;
height: 20px;
z-index: 2;
background: #eee;
}
div {
position: relative;
bottom: 0;
width: 400px;
padding: 20px;
background: $primary-color;
box-shadow: 4px 13px 30px 1px rgba(252, 56, 56, 0.2);
border-radius: 5px;
display: flex;
align-items: center;
time {
position: absolute;
background: #f5af19;
width: 80px;
height: 30px;
top: -15px;
border-radius: 5px;
display: flex;
justify-content: center;
align-items: center;
letter-spacing: 2px;
}
div {
height: 100px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
p {
text-align: center;
}
}
.discovery {
margin-right: 10px;
}
.scientist {
}
}
&:nth-of-type(odd) {
> div {
left: 45px;
}
}
&:nth-of-type(even) {
> div {
left: -439px;
}
}
}
}
}
// ANIMATION
.timeline {
ul {
li {
div {
visibility: hidden;
opacity: 0;
transition: all 0.5s ease-in-out;
}
&:nth-of-type(odd) {
div {
transform: translate3d(100px, -10px, 0) rotate(10deg);
}
}
&:nth-of-type(even) {
div {
transform: translate3d(-100px, -10px, 0) rotate(10deg);
}
}
&.in-view {
div {
transform: none;
visibility: visible;
opacity: 1;
}
}
}
}
}
@media screen and (max-width: 900px) {
.timeline {
ul {
li {
div {
width: 250px;
flex-direction: column;
div {
width: 80%;
margin: 10px;
}
}
&:nth-of-type(even) {
> div {
left: -289px;
}
}
}
}
}
}
@media screen and (max-width: 600px) {
body {
background: #8bfff4;
}
.timeline {
ul {
li {
margin-left: 20px;
div {
width: calc(100vw - 91px);
}
&:nth-of-type(even) {
> div {
left: 45px;
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.