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 |
Single page website | 2,688 Kb |
Smooth scroll | 4,915 Kb |
GSAP Parallax | 2,513 Kb |
Simple GSAP Slider | 2,839 Kb |
Fullscreen image in Canvas | 2,268 Kb |
Page Header animation | 2,828 Kb |
Medium.com style header effect | 2,828 Kb |
Simple one page header concept | 2,530 Kb |
Fullscreen slides with TweenLite, CSSPlugin and ScrollToPlugin | 4,226 Kb |
GIF-like animation with single image | 1,807 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 |
Animated SVG stroke-dasharray | Netsi1964 | 3,179 Kb |
Sticky div | Kaslab | 2,225 Kb |
Example SVGZ Data URI | Joeyhoer | 2,981 Kb |
Nav Test -- cats 1 | Payls | 4,735 Kb |
Progressively reveal dots on a Bezier curve | GreenSock | 2,489 Kb |
Mini Profile | Frytyler | 3,828 Kb |
Display properties | Hamzaerbay | 1,886 Kb |
FreeCodeCamp - Simon Game | Ivhed | 8,481 Kb |
Mega menu | DimaZubkov | 5,066 Kb |
Headroom.js demo | WickyNilliams | 3,982 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!