
WiseDan
Gsap.js - how to load content in my home page when user scrolling?
hi everybody , am new in gsap.js
so i wanted load content in my home page when user scrolling , but
since am reading the documentation , when i include the cdn link , nothing is happen in the page like ( gsap.to(“.box”, { x:200, backgroundColor: “blue” })
please help with great example using gsap.js with cdn in your projet and have all done in the browser !!
Most Liked

gulshan212
Well, you can just copy the below code for getting what you are looking for.
<!DOCTYPE html>
<html>
<head>
<title>GSAP Scroll Animation Example</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.8.0/gsap.min.js"></script>
<style>
body {
height: 200vh; /* To make the page scrollable */
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
.box {
width: 100px;
height: 100px;
background-color: red;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<div class="box"></div>
<script>
<script>
// Wait for the DOM to be ready
document.addEventListener("DOMContentLoaded", function() {
// GSAP animation
gsap.to(".box", {
x: 200,
backgroundColor: "blue",
duration: 1, // Animation duration in seconds
scrollTrigger: {
trigger: ".box", // Element that triggers the animation
start: "top center", // Animation starts when this point of the element is at the top center of the viewport
end: "bottom center", // Animation ends when this point of the element is at the bottom center of the viewport
scrub: true, // Smoothly scrubs the animation as you scroll
},
});
});
</script>
</script>
</body>
</html>
Thanks
1
Popular Frontend topics

Hi I have a gallery site which displays paintings according to selected category (oils, water-color, etc.) “on:click” event.
When this e...
New

Hi to everyone,
we are experiencing a 401 error related to the connection of the websocket (in reference to our web app); we are unable ...
New

Hi this is Palak Sharma
I am new here and I found this community while researching about JavaScript over the internet.
Well I have comp...
New

Background
I have a button that may be disabled or not, depending on a set of conditions. I want to disable/enable the button without hav...
New

Background
I have a custom component in my LiveView, which is basically a group of checkboxes.
I want to add a new attribute to my custo...
New

We are developing on Samsung Tab Active 4 Pro using Android Studio, kotlin and java. We are getting what we think are app deadlocks. The ...
New

I am creating an app that allows user to enter values and depending on the value a number of textviews are changed programmatically from ...
New

First time building an app. It will run for Android and also for iPhone 15 but will not for iPod. Not sure why or where to even begin. ...
New

hello , i should code a cluster like image bellow we have no challenge in coding backend but in front need some clue to do this
its a dy...
New

would it be backwards if I’m learning react? last time I used UI library (aside from LiveView) was Elm (not much) and that was eons ago.
New
Other popular topics

New

poll
poll
Be sure to check out @Dusty’s article posted here: An Introduction to Alternative Keyboard Layouts It’s one of the best write-...
New

There’s a whole world of custom keycaps out there that I didn’t know existed!
Check out all of our Keycaps threads here:
https://forum....
New

Not sure if following fits exactly this thread, or if we should have a hobby thread…
For many years I’m designing and building model air...
New

Seems like a lot of people caught it - just wondered whether any of you did?
As far as I know I didn’t, but it wouldn’t surprise me if I...
New

Saw this on TikTok of all places! :lol:
Anyone heard of them before?
Lite:
New

This is going to be a long an frequently posted thread.
While talking to a friend of mine who has taken data structure and algorithm cou...
New

Author Spotlight
Mike Riley
@mriley
This month, we turn the spotlight on Mike Riley, author of Portable Python Projects. Mike’s book ...
New

Large Language Models like ChatGPT say The Darnedest Things.
The Errors They MakeWhy We Need to Document Them, and What We Have Decided ...
New

If you’re getting errors like this:
psql: error: connection to server on socket “/tmp/.s.PGSQL.5432” failed: No such file or directory ...
New
Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /rails
- /js
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /emacs
- /java
- /haskell
- /onivim
- /svelte
- /typescript
- /crystal
- /c-plus-plus
- /kotlin
- /tailwind
- /gleam
- /ocaml
- /react
- /flutter
- /elm
- /vscode
- /ash
- /opensuse
- /centos
- /php
- /deepseek
- /html
- /scala
- /zig
- /textmate
- /sublime-text
- /nixos
- /debian
- /lisp
- /agda
- /react-native
- /kubuntu
- /arch-linux
- /ubuntu
- /revery
- /spring
- /manjaro
- /django
- /diversity
- /lua
- /nodejs
- /c
- /slackware
- /julia
- /markdown