Train Journey
A train steams in from the left, stops to load a package, then continues into a tunnel on the right — a narrative cargo-transfer animation with a dashed track.
Train Journey
by FreeCsStyles Dev's
Character AnimationNarrative
🌐HTML/CSS🎨Tailwind⚛️React💚Vue🅰️Angular🔥Svelte☁️LWC
#train#journey#cargo#transfer#shipping#logistics#track#narrative
Embed this component
Paste this snippet into any site — the design renders in a sandboxed iframe served from /embed/train-journey.
<iframe src="/embed/train-journey" sandbox="allow-scripts" loading="lazy" title="Train Journey" style="border:0;width:100%;height:480px;overflow:hidden"></iframe>Implementation code
Copy the HTML and CSS for Train Journey, or grab a framework-specific implementation. The HTML and CSS variants are self-contained; framework variants assume that framework's project setup.
HTML
<button class="btn-train" id="trainBtn">
<span class="train">🚂</span>
<span class="pkg">📦</span>
<span class="tunnel">🕳️</span>
<span class="text">Transfer</span>
</button>
<script>
const trainBtn = document.getElementById('trainBtn');
trainBtn.addEventListener('click', function() {
if(this.classList.contains('is-moving')||this.classList.contains('is-loaded')) return;
this.classList.add('is-moving');
setTimeout(() => this.classList.add('is-loaded'), 1500);
setTimeout(() => {
this.classList.remove('is-moving','is-loaded');
this.classList.add('is-arrived');
this.querySelector('.text').textContent = 'Arrived';
}, 2500);
setTimeout(() => {
this.classList.remove('is-arrived');
this.querySelector('.text').textContent = 'Transfer';
}, 4500);
});
</script>CSS
.btn-train{width:160px;height:50px;border-radius:12px;border:none;background:#0284c7;color:#fff;font-size:16px;font-weight:700;cursor:pointer;position:relative;display:flex;align-items:center;justify-content:center;overflow:hidden;transition:all .4s cubic-bezier(.4,0,.2,1);font-family:system-ui,sans-serif;border-bottom:3px dashed #7dd3fc}.btn-train .train{position:absolute;left:-40px;font-size:22px;transition:left 1.5s linear;z-index:2}.btn-train .pkg{position:absolute;left:50%;top:15px;transform:translateX(-50%);font-size:14px;transition:.2s}.btn-train .tunnel{position:absolute;right:-10px;top:10px;font-size:24px;z-index:3}.btn-train.is-moving .text{opacity:0}.btn-train.is-moving .train{left:50%}.btn-train.is-loaded .pkg{opacity:0}.btn-train.is-loaded .train{left:160px;transition:left 1s linear}.btn-train.is-arrived{background:#10b981;border-color:#34d399}Tailwind CSS
<button class="w-[160px] h-[50px] rounded-xl border-none bg-sky-600 text-white font-bold cursor-pointer relative flex items-center justify-center overflow-hidden transition-all duration-[400ms]" style="border-bottom:3px dashed #7dd3fc">
<span class="train absolute -left-10 text-[22px] z-[2] transition-all duration-[1500ms] linear">🚂</span>
<span class="pkg absolute text-sm" style="left:50%;top:15px;transform:translateX(-50%)">📦</span>
<span class="tunnel absolute text-2xl z-[3]" style="right:-10px;top:10px">🕳️</span>
<span class="text">Transfer</span>
</button>React
import { useState } from 'react';
export function TrainButton() {
const [stage, setStage] = useState('idle');
const handleClick = () => {
if (stage !== 'idle') return;
setStage('moving');
setTimeout(() => setStage('loaded'), 1500);
setTimeout(() => setStage('arrived'), 2500);
setTimeout(() => setStage('idle'), 4500);
};
const trainLeft = stage === 'idle' ? -40 : stage === 'moving' ? 'calc(50% - 20px)' : stage === 'loaded' ? 160 : -40;
return (
<button
onClick={handleClick}
disabled={stage !== 'idle'}
style={{
width: 160, height: 50, borderRadius: 12, border: 'none',
background: stage === 'arrived' ? '#10b981' : '#0284c7',
borderBottom: `3px dashed ${stage === 'arrived' ? '#34d399' : '#7dd3fc'}`,
color: 'white', fontSize: 16, fontWeight: 'bold', cursor: 'pointer',
position: 'relative', display: 'flex', alignItems: 'center',
justifyContent: 'center', overflow: 'hidden', fontFamily: 'system-ui,sans-serif',
transition: 'all 0.4s cubic-bezier(0.4,0,0.2,1)',
}}
>
<span style={{
position: 'absolute', fontSize: 22, zIndex: 2,
left: trainLeft, transition: stage === 'moving'
? 'left 1.5s linear' : stage === 'loaded' ? 'left 1s linear' : 'left 0.3s'
}}>🚂</span>
<span style={{
position: 'absolute', fontSize: 14,
left: '50%', top: 15, transform: 'translateX(-50%)',
opacity: stage === 'loaded' || stage === 'arrived' ? 0 : 1,
transition: 'opacity 0.2s'
}}>📦</span>
<span style={{ position: 'absolute', fontSize: 24, zIndex: 3, right: -10, top: 10 }}>🕳️</span>
<span style={{ opacity: stage === 'moving' || stage === 'loaded' ? 0 : 1, transition: '0.3s' }}>
{stage === 'arrived' ? 'Arrived' : 'Transfer'}
</span>
</button>
);
}Vue
<template>
<button class="btn-train" :class="stage" @click="handleClick" :disabled="stage!=='idle'">
<span class="train" :style="{ left: trainLeft }">🚂</span>
<span class="pkg" :style="{ opacity: pkgOpacity }">📦</span>
<span class="tunnel">🕳️</span>
<span class="text">{{ stage==='arrived' ? 'Arrived' : 'Transfer' }}</span>
</button>
</template>
<script setup>
import { ref, computed } from 'vue';
const stage = ref('idle');
const trainLeft = computed(() => stage.value==='idle'?'-40px':stage.value==='moving'?'calc(50% - 20px)':stage.value==='loaded'?'160px':'-40px');
const pkgOpacity = computed(() => (stage.value==='loaded'||stage.value==='arrived')?0:1);
function handleClick() {
if (stage.value !== 'idle') return;
stage.value = 'moving';
setTimeout(() => stage.value = 'loaded', 1500);
setTimeout(() => stage.value = 'arrived', 2500);
setTimeout(() => stage.value = 'idle', 4500);
}
</script>
<style scoped>
.btn-train{width:160px;height:50px;border-radius:12px;border:none;background:#0284c7;color:#fff;font-size:16px;font-weight:700;cursor:pointer;position:relative;display:flex;align-items:center;justify-content:center;overflow:hidden;transition:all .4s;border-bottom:3px dashed #7dd3fc}.btn-train .train{position:absolute;font-size:22px;z-index:2;transition:left 1.5s linear}.btn-train .pkg{position:absolute;left:50%;top:15px;font-size:14px;transform:translateX(-50%);transition:.2s}.btn-train .tunnel{position:absolute;right:-10px;top:10px;font-size:24px;z-index:3}.btn-train.arrived{background:#10b981;border-color:#34d399}.btn-train.moving .text,.btn-train.loaded .text{opacity:0}.btn-train.loaded .train{left:160px}</style>Svelte
<script>
let stage = 'idle';
$: trainLeft = stage === 'idle' ? '-40px' : stage === 'moving' ? 'calc(50% - 20px)' : stage === 'loaded' ? '160px' : '-40px';
$: pkgOpacity = (stage === 'loaded' || stage === 'arrived') ? 0 : 1;
function handleClick() { if (stage !== 'idle') return; stage = 'moving'; setTimeout(() => stage = 'loaded', 1500); setTimeout(() => stage = 'arrived', 2500); setTimeout(() => stage = 'idle', 4500); }
</script>
<button class="btn-train" class:is-arrived={stage==='arrived'} on:click={handleClick} disabled={stage!=='idle'}>
<span class="train" style="left: {trainLeft}">🚂</span><span class="pkg" style="opacity: {pkgOpacity}">📦</span><span class="tunnel">🕳️</span>
<span class="text">{stage==='arrived' ? 'Arrived' : 'Transfer'}</span>
</button>
<style>
.btn-train{width:160px;height:50px;border-radius:12px;border:none;background:#0284c7;color:#fff;font-size:16px;font-weight:700;cursor:pointer;position:relative;display:flex;align-items:center;justify-content:center;overflow:hidden;transition:all .4s;border-bottom:3px dashed #7dd3fc}.btn-train .train{position:absolute;font-size:22px;z-index:2;transition:left 1.5s linear}.btn-train .pkg{position:absolute;left:50%;top:15px;font-size:14px;transform:translateX(-50%);transition:.2s}.btn-train .tunnel{position:absolute;right:-10px;top:10px;font-size:24px;z-index:3}.btn-train.is-arrived{background:#10b981;border-color:#34d399}
</style>Angular
import { Component } from '@angular/core';
@Component({
selector: 'app-train-button',
template: `<button class="btn-train" [class.is-arrived]="stage==='arrived'" (click)="handleClick()" [disabled]="stage!=='idle'">
<span class="train" [style.left]="trainLeft">🚂</span><span class="pkg" [style.opacity]="pkgOpacity">📦</span><span class="tunnel">🕳️</span>
<span class="text">{{ stage==='arrived' ? 'Arrived' : 'Transfer' }}</span>
</button>`,
styles: [`.btn-train{width:160px;height:50px;border-radius:12px;border:none;background:#0284c7;color:#fff;font-size:16px;font-weight:700;cursor:pointer;position:relative;display:flex;align-items:center;justify-content:center;overflow:hidden;transition:all .4s;border-bottom:3px dashed #7dd3fc}.btn-train .train{position:absolute;font-size:22px;z-index:2;transition:left 1.5s linear}.btn-train .pkg{position:absolute;left:50%;top:15px;font-size:14px;transform:translateX(-50%);transition:.2s}.btn-train .tunnel{position:absolute;right:-10px;top:10px;font-size:24px;z-index:3}.btn-train.is-arrived{background:#10b981;border-color:#34d399}.btn-train.is-arrived .text{opacity:1}`]
})
export class TrainButtonComponent { stage='idle';get trainLeft(){return this.stage==='idle'?'-40px':this.stage==='moving'?'calc(50% - 20px)':this.stage==='loaded'?'160px':'-40px'}get pkgOpacity(){return(this.stage==='loaded'||this.stage==='arrived')?0:1}handleClick(){if(this.stage!=='idle')return;this.stage='moving';setTimeout(()=>this.stage='loaded',1500);setTimeout(()=>this.stage='arrived',2500);setTimeout(()=>this.stage='idle',4500);}}LWC — HTML template
<template><button class="btn-train" onclick={handleClick} disabled={disabled}>
<span class="train" style={trainStyle}>🚂</span><span class="pkg" style={pkgStyle}>📦</span><span class="tunnel">🕳️</span>
<span class="text">{label}</span>
</button></template>LWC — JavaScript
import { LightningElement } from 'lwc';
export default class TrainButton extends LightningElement {
stage = 'idle';
get disabled() { return this.stage !== 'idle'; }
get label() { return this.stage==='arrived'?'Arrived':'Transfer'; }
get trainStyle() { const l={'idle':'-40px','moving':'calc(50% - 20px)','loaded':'160px'};return `position:absolute;font-size:22px;z-index:2;left:${l[this.stage]||'-40px'};transition:left ${this.stage==='loaded'?'1s':this.stage==='moving'||this.stage==='idle'?'1.5s':'0.3s'} linear`; }
get pkgStyle() { return `position:absolute;font-size:14px;left:50%;top:15px;transform:translateX(-50%);opacity:${(this.stage==='loaded'||this.stage==='arrived')?0:1};transition:opacity 0.2s`; }
handleClick() { if(this.stage!=='idle')return;this.stage='moving';setTimeout(()=>this.stage='loaded',1500);setTimeout(()=>this.stage='arrived',2500);setTimeout(()=>this.stage='idle',4500); }
}LWC — CSS
.btn-train{width:160px;height:50px;border-radius:12px;border:none;background:#0284c7;color:#fff;font-size:16px;font-weight:700;cursor:pointer;position:relative;display:flex;align-items:center;justify-content:center;overflow:hidden;transition:all .4s;border-bottom:3px dashed #7dd3fc}.btn-train .tunnel{position:absolute;right:-10px;top:10px;font-size:24px;z-index:3}.btn-train.is-arrived{background:#10b981;border-color:#34d399}LWC — Configuration
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>59.0</apiVersion>
<isExposed>true</isExposed>
<targets><target>lightning__AppPage</target><target>lightning__RecordPage</target><target>lightning__HomePage</target></targets>
</LightningComponentBundle>Where Train Journey fits
- Transfer Actions
- Shipping
- Logistics
- Data Migration
- Process Flow
Interaction states & animations
- Multi-stage
- Character
- Slide
- Loading
- Tunnel
Topics
- #train
- #journey
- #cargo
- #transfer
- #shipping
- #logistics
- #track
- #narrative
Accessibility notes
Button auto-resets after 4.5s. Use aria-live regions to announce each stage.
Browser support
- All modern browsers