Page Header animation
How do I make an page header animation?
I had to create a very fast and optimized page that had a sophisticated header on-scroll animation ( like 3D parallax ). I could add TweenLite+CSSPlugin ( 21.09KB ), but decided to add nothing more. So this is kind of the most simple, Vanilla JS, yet very flexible and fast header scroll-in effect;. What is a page header animation? How do you make a page header animation? This script and codes were developed by Chrysto on 16 July 2022, Saturday.
Page Header animation - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Page Header animation</title> <script src="http://s.codepen.io/assets/libs/modernizr.js" type="text/javascript"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <header> <div id="box1"></div> <div id="box2"></div> <div id="box3"></div>
</header> <script src='http://cdnjs.cloudflare.com/ajax/libs/gsap/latest/TweenLite.min.js'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/gsap/latest/plugins/CSSPlugin.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Page Header animation - Script Codes CSS Codes
body { min-height:2000px;
}
header { position:absolute; top:0; left:0; width:100%; height:500px; background-color:#e7e7e7; overflow: hidden;
}
div[id^=box]{ position: absolute;
}
#box1 { left:10%; bottom:20%; width:300px; height:300px; background-color:red;
}
#box2 { top:10%; left:40%; width:200px; height:130px; background-color:#000;
}
#box3 { top:30%; right:20%; width:12%; height:17%; background-color:green;
}
Page Header animation - Script Codes JS Codes
document.addEventListener("DOMContentLoaded", function(){ //needed to get scrollTop position on IE9- var documentElement = document.documentElement; //Heder height var targetPosY = 500; /* A couple of notes here 1) For such a thing, normally I would just use a TimelineMax. It is amazingly flexible and is tend for just this kind of animations. The idea of this pen is to make things fast and simple as possible; 2) Actually, I can pass string to TweenLite.to("element ID", time, {...}); but I prefer to pass DOM Element 3) If you add your own TweenLite's and style it, actually can get pritty nice results */ var tweens = [ TweenLite.to( document.querySelector("#box1"), 1, {css:{force3D:true, scale:1.2, y:100}, paused:true}), TweenLite.to( document.querySelector("#box2"), 1, {css:{force3D:true, scale:1.6, y:200, x:-100, alpha: 0.5}, paused:true}), TweenLite.to( document.querySelector("#box3"), 1, {css:{force3D:true, scale:2.6, y:150, x:50, rotation:45}, paused:true}) ]; window.onscroll = function (event) { ( !! window.requestAnimationFrame) ? requestAnimationFrame(onScroll) : onScroll(); } function onScroll(){ //have to restrict it into range, because on OSX it can get negative values //http://bassta.bg/2013/05/restrict-a-number-to-a-range/ var top = Math.max(Math.min(window.pageYOffset || documentElement.scrollTop, targetPosY), 0); if(top <= targetPosY){ var progress = (top / targetPosY); Array.prototype.forEach.call(tweens, function(tween){ tween.progress(progress); }); } }
});//end on DOMContentLoaded
Developer | Chrysto |
Username | bassta |
Uploaded | July 16, 2022 |
Rating | 3.5 |
Size | 2,828 Kb |
Views | 48,576 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
A Pen by Chrysto | 2,057 Kb |
Fullscreen image in Canvas | 2,268 Kb |
Medium.com style header effect | 2,828 Kb |
GIF-like animation with single image | 1,807 Kb |
TweenLite staggerTo | 2,495 Kb |
Lastik menu | 2,257 Kb |
Simple one page header concept | 2,530 Kb |
Footer concept | 2,210 Kb |
Click outside element | 1,993 Kb |
Smooth scroll | 4,915 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Magnus 3 | ARocketfish | 7,944 Kb |
Sass random color animation | Jotavejv | 4,827 Kb |
Z-index demo | Kblh | 1,534 Kb |
Popup Modal | Aldlevine | 3,696 Kb |
Portfolio Layout Flex | Lahvjal | 3,489 Kb |
VerbalExpressions Converter | Cmalven | 2,607 Kb |
12 DAYS OF XMAS | Proto78 | 2,313 Kb |
Mesmerizing octopus | Jllodra | 3,549 Kb |
Text Blocks Over Image, Updated | KatieK2 | 3,122 Kb |
CSS Colors | Alexpate | 2,232 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!