
The elastic button
Buttons, Hover, Text
The «Donate» button of a tree-planting fund, in the style of product interface pieces, on white: on hover the amounts fan out above the button, the chosen one drops into it, the button turns green and says «Thank you», and a small tree grows on its edge for every five dollars while the amount raised rolls up and the bar moves on.
A folder that runs on its own: index.html, style.css, script.js and the libraries from a CDN. The React and Vue tabs hold the same demo as a ready component, which switches its animations off when it leaves the page.
<!doctype html>
<!--
"Donate trees button" from Animorio · https://animorio.com
License: free on your own sites and your clients’ sites, paid work included.
Not for resale, redistribution, templates or code collections · https://animorio.com/en/license/
-->
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>The Donate button with trees growing on its edge</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/wdth.css">
<link rel="stylesheet" href="style.css">
</head>
<body>
<main class="stage" data-stage>
<!-- a tree-planting fund: the amounts fan out over the button, the chosen one drops in,
and a tree grows on the button's top edge for every five dollars while the bar below fills -->
<div class="donor" data-donor>
<div class="pad" data-pad>
<div class="amounts" data-amounts role="group" aria-label="Choose an amount">
<button class="amt" type="button" data-amt="5" tabindex="-1"><span>$5</span></button>
<button class="amt" type="button" data-amt="10" tabindex="-1"><span>$10</span></button>
<button class="amt" type="button" data-amt="25" tabindex="-1"><span>$25</span></button>
</div>
<svg class="grove" data-grove viewBox="0 0 220 44" aria-hidden="true"></svg>
<button class="donate" type="button" data-donate data-autoclic aria-expanded="false">
<span class="donate__fill" data-fill aria-hidden="true"></span>
<span class="donate__face" data-face>
<svg class="sap" data-sap viewBox="0 0 20 20" aria-hidden="true">
<path class="sap__stem" d="M10 17.5V9.2"></path>
<path class="sap__leaf" data-leaf-l d="M10 11.6C7.2 11.8 5.2 10.2 4.8 7.4 7.6 7.1 9.6 8.6 10 11.6Z"></path>
<path class="sap__leaf" data-leaf-r d="M10 9.4C10.3 6.4 12.4 4.6 15.4 4.6 15.4 7.6 13.2 9.4 10 9.4Z"></path>
<path class="sap__soil" d="M6.4 17.5h7.2"></path>
</svg>
<span class="donate__words">
<span class="donate__label" data-idle>Donate</span>
<span class="donate__label donate__label--done" data-done aria-hidden="true">
<svg class="tick" viewBox="0 0 16 16"><path data-tick d="M3.4 8.4 6.6 11.4 12.6 4.8"></path></svg>
<span data-done-text>Thank you</span>
</span>
</span>
</span>
</button>
</div>
<div class="raised" data-raised>
<p class="raised__line">
<span class="raised__sum" data-sum>$1,240</span>
<span class="raised__of">of $2,000 raised</span>
</p>
<div class="bar" aria-hidden="true">
<span class="bar__fill" data-bar></span>
<span class="bar__gain" data-gain></span>
</div>
<p class="raised__note"><span data-trees>248</span> trees planted with Rowan Trust</p>
</div>
</div>
<svg class="ghost" data-ghost viewBox="0 0 24 24" aria-hidden="true"><path d="M5 3.2 19.2 11l-6.3 1.6-3.3 5.9Z"></path></svg>
</main>
<script src="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/gsap.min.js"></script>
<script src="script.js"></script>
</body>
</html>Change values, colours and text with the controls and watch the animation respond live. Or write in the code yourself. Then download the folder with your changes.
25 values to change
With the Animorio connector, Claude Code, ChatGPT, Cursor or VS Code take it from here, guide included, and fit it into your project. Paste this request:
Take “Donate trees button” from Animorio and fit it into my siteThe three pills all sit in the same spot, above the centre of the button, small and transparent. On opening, GSAP takes each one to its place on a shallow arc (x minus 64, 0 and 64, the middle one 8 pixels higher, rotated minus 7, 0 and 7 degrees) with back.out and a small delay between them; on closing they go back in reverse order.
The chosen pill drops 52 pixels and shrinks to 0.45 with power2.in, fading as it reaches the button. At that moment the button squashes (0.92 in height, 1.03 in width) and comes back with elastic.out: you feel the hit.
The trees are SVG groups created on the fly, one every PER_TREE dollars, in a drawing resting on the button’s top edge. Each has a shadow, a trunk and a crown made of two circles and a highlight: they grow in that order, each with its svgOrigin at the base, and then the group sways with an endless yoyo of a different length for every tree.
The amount raised is a number animated by GSAP and rewritten on every frame with toLocaleString; the bar is two layers with scaleX, the black of what was there and the green up to the new total, which melts into the black on the way back.
A delayedCall of HOLD seconds sinks the trees back (first the crown, then the trunk), turns off the button’s green and brings back «Donate». The autopilot awaits the tweens as promises and stops at the first real touch, to start again after eight quiet seconds.
| Name | File | Default | What it changes |
|---|---|---|---|
FAN | script.js | 0.5 | How long the spring that fans the amounts out above the button lasts, in seconds. |
GROW | script.js | 0.75 | How long a tree takes to grow on the button’s edge, in seconds. |
HOLD | script.js | 2.6 | How many seconds «Thank you» stays before «Donate» comes back. |
PER_TREE | script.js | 5 | How many dollars make a tree. |
START_RAISED | script.js | 1240 | How much has already been raised at the start, in dollars. |
GOAL | script.js | 2000 | The fund’s goal, in dollars. |
INK | script.js | #0a0a0a | The colour of the button and the bar. |
ACCENT | script.js | #2f8f5b | The green of the button when it thanks you and of the new part of the bar. |
LEAF | script.js | #3da56b | The green of the trees’ crowns. |
For the «Donate» button on the site of a charity, a fundraiser or an environmental project: whoever gives picks the amount without leaving the page and sees straight away what the gift has done.
On the phone the amounts open by tapping the button and close by tapping outside; the pills are 34 pixels tall and the fan fits within 182 pixels, so it fits even in the narrowest box.
The amounts fade in in place, the chosen one fades without dropping, the button turns green and changes its label without sliding, the trees fade in and out without swaying, the amount raised changes at once and the drawn pointer is not shown.
GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.
Compressed with gzip, the three demo files weigh 7.2 KB; the libraries: GSAP 28 KB.
Tested on 30 October 2026
Use it in your own projects and in your clients’ projects. Do not resell it or redistribute it as is. GSAP stays under its own Standard license. Full license.
Support Animorio
Animorio stays free thanks to the people who support it. If you like, buy us a coffee: it helps us make the next animations.
You asked for
We made it for you: it’s in the library, with the preview, the Playground and the code to copy.
An animation you can’t find, or a site to take apart in the journal: tell us which. We pick the next ones from here.
With your account’s email and password.
or with your email
You’re signed in as .
With your account, you can download the zip of every animation and every pack, for free.