This zone is sleeping right now! ZzzZZzzz

Better not disturb it! ~You go to the petrol station and buy a slushy instead, everything is cool!~

This area will open again in 000.beats!

(Learn about Swatch Time)

Some other zones are awake :^]


Artifacts Gallery Guilds Search Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining?
September 07, 2026 - @511.12
Activity rating: Three Stars Posts & Arts: 45/1k.beats Random | Recent Posts | Guild Recents
News: :defrag: Lo and Behold :defrag: Guild Events: There are no events!

+  MelonLand Forum
|-+  Life & The Web
| |-+  ✁ ∙ Web Crafting
| | |-+  ☔︎ ∙ I need Help!
| | | |-+  How to do frame-by-frame animation with javascript?


« previous next »
Pages: [1] Print Embed
Author Topic: How to do frame-by-frame animation with javascript?  (Read 69 times)
oro_junestar
Casual Poster ⚓︎
*
View Profile WWWArt


I'm the ghost, actually. But yeah, rockage.
⛺︎ My Room

Guild Memberships:
Artifacts:
star cutieGreat Posts PacmanJoined 2026!
« on: September 06, 2026 @15.41 » Embed

I've got a pretty complicated idea; I want to make an interactable pet window with my cat character, Hope. I've split her into multiple parts to allow for interactions like petting her head, poking her eyes, or swapping her bandana.
This is how she looks on the site:

This is how she's arranged in the code:


My question is, how can I use scripts to move the individual parts to set positions in set timing?

I want to start with a tail wag animation like this:

Logged

Pac-Man! My readings suggest a nearby ghost to rescue! Either that, or I have spaghetti sauce on my monitor.

Artifact Swap: artifact guyThe Worm is creeping around Melonland profiles!Blue ham-ham rangerGay NeurodivergentBugbooooCherryLil ghost friendQurbyAwful Posts Pacmansuck itGarykyubey sittingLazy (part1)Lazy (part2)Yarn kittyVillager Spawn Egg
MediocreMetastasis
Sr. Member ⚓︎
****
View Profile WWWArt


Wishlist Skelecool: Remnants Please!!!
⛺︎ My Room
Itch.io: My Games

Guild Memberships:
Artifacts:
Joined 2025!
« Reply #1 on: September 06, 2026 @614.50 » Embed

There are multiple ways I can see you tackling this problem

Theres the <canvas> element. You do need to heavily use js and a bit complicated but you can easily draw images with set positions, this method is basically like rendering game graphics. This option would give you the most freedom.

You can use css animations and interchange them using js
example css animation
/* The animation code */

CSS:
@keyframes tail-wag {
  from {transfrom: rotate(45);}
  to {transform: rotate(-45);}
}

/* The element to apply the animation to */
.tail-wag {
  animation-name: tail-wag;
  animation-duration: 4s;
}
JS:
const tail = document.getElementByID("tail");

// 1. Add the animation
tail.classList.add('tail-wag');

// 2. Remove the animation
tail.classList.remove('tail-wag');

// 3. Toggle it on/off (e.g., on a button click)
tail.classList.toggle('tail-wag');

//May work IDK just throwing stuff at a wall
[close]

Or good old updating the rotation property using a setInterval() function

2nd one seems the easiest

« Last Edit: September 06, 2026 @618.04 by MediocreMetastasis » Logged


Artifact Swap: Sad DoggoNeutral Doggo
Pages: [1] Print Embed 
« previous next »
 

Melonking.Net © Always and ever was! SMF 2.0.19 | SMF © 2021 | Privacy Notice | Send Feedback | Supporters ♥ Forum Guide | Rules | RSS | WAP | Mobile


MelonLand Badges and Other Melon Sites!

MelonLand Project! Visit the MelonLand Forum! Support the Forum
Visit Melonking.Net! Visit the Gif Gallery! Pixel Sea TamaNOTchi
@000 MelonLand Editor Recent Edits Tenement Arcade Want to Login or Join ? Forum Art Hub Chat Webring Web Guides Graphics Catalogue Wiki Newsletters Image Stream
Melon's Sites TamaNotchi Textures PixelSea GifyPet MoMG Ozwomp Online Loom Videos Leaky Webring Melonking
Tools Melon Software ArtHub Embed Maker ML Passports
Outlinks Frutiger Aero Forum Onio Club m15o's Web Services 32Bit Cafe iMood Webrings Internet Phone Book HTML Energy Declarations Hackers & Designers
Zap!
Minecraft: Online
Join: craft.melonking.net