GSAP Parallax
How do I make an gsap parallax?
Just a quick pen showing how to create a parallax effect on mouse move with TweenMax. Position element / set elements via CSS, set speed via data attribute. What is a gsap parallax? How do you make a gsap parallax? This script and codes were developed by Chrysto on 16 July 2022, Saturday.
GSAP Parallax - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>GSAP Parallax </title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div id="parallax-container"> <div class="box box-1 parallax" data-speed-x="200" data-speed-y="200"></div> <div class="box box-2 parallax" data-speed-x="80" data-speed-y="80"></div> <div class="box box-3 parallax" data-speed-x="30" data-speed-y="40"></div>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/gsap/latest/TweenMax.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
GSAP Parallax - Script Codes CSS Codes
#parallax-container{ position: relative; width: 100%; height: 100%; padding: 0px; margin: 0px;
} .box{ position: absolute; width: 200px; height: 200px; } .box-1{ background-color: #df7b7b; top: 100px; left: 30%; } .box-2{ background-color: rgba(217,109,187,0.5); top: 120px; left: 40%; } .box-3{ background-color: rgba(13,98,189,0.5); top: 130px; left: 50%; }
GSAP Parallax - Script Codes JS Codes
$(function(){ /* Author: Chrysto Panayotov ( [email protected] ) For GreenSock forums user azuki License : http://bassta.bg/license/ */ var $parallaxContainer = $("#parallax-container"); //our container var $parallaxItems = $parallaxContainer.find(".parallax"); //elements var fixer = 0.0008; //experiment with the value $(document).on("mousemove", function(event){ var pageX = event.pageX - ($parallaxContainer.width() * 0.5); //get the mouseX - negative on left, positive on right var pageY = event.pageY - ($parallaxContainer.height() * 0.5); //same here, get the y. use console.log(pageY) to see the values //here we move each item $parallaxItems.each(function(){ var item = $(this); var speedX = item.data("speed-x"); var speedY = item.data("speed-y"); /*TweenLite.to(item, 0.5, { x: (item.position().left + pageX * speedX )*fixer, //calculate the new X based on mouse position * speed y: (item.position().top + pageY * speedY)*fixer });*/ //or use set - not so smooth, but better performance TweenLite.set(item, { x: (item.position().left + pageX * speedX )*fixer, y: (item.position().top + pageY * speedY)*fixer }); }); }); });
Developer | Chrysto |
Username | bassta |
Uploaded | July 16, 2022 |
Rating | 3.5 |
Size | 2,513 Kb |
Views | 131,560 |
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 |
Medium.com style header effect | 2,828 Kb |
Smooth scroll | 4,915 Kb |
Footer concept | 2,210 Kb |
Fullscreen Parallax | 3,313 Kb |
TweenLite staggerTo | 2,495 Kb |
A Pen by Chrysto | 2,057 Kb |
Page Header animation | 2,828 Kb |
Single page website | 2,688 Kb |
Fullscreen image in Canvas | 2,268 Kb |
Fullscreen slides with TweenLite, CSSPlugin and ScrollToPlugin | 4,226 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 |
V.35 The Monolith Update - Hero Release Notes | Jordan | 12,045 Kb |
Old calculator | Gnarfugh | 2,815 Kb |
Random Gradients - JS | Aldlevine | 2,026 Kb |
FCC Portfolio | Cmwebby | 4,304 Kb |
Coburg Banks SVG Logo | Mjtweaver | 3,875 Kb |
Price Comparison Table | Orrinward | 3,459 Kb |
This in constructor context | _shree33 | 1,718 Kb |
Toggle menu | Seyedi | 2,279 Kb |
Banner Ad | Raquellorenzana | 4,172 Kb |
RRC wrapSwitch | Pshrmn | 2,922 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!