Журнал Тильды
/
Библиотека промптов
/
Этапы работы на сайте с анимацией цифр при скролле
Анимация
Этапы работы на сайте с анимацией цифр при скролле
Блок «Этапы работы» на сайте: при скролле крупная цифра перестраивается в следующую, рядом меняются фото и описание.
Промпт
Вы можете скопировать промпт и вставить его в вайб блок в поле ввода. Подробнее в инструкции.
5 этапов выпечки: слева морфинг цифры, справа фото/текст.

5 article в HTML: номера/тексты data-tilda-edit="y", img data-tilda-img="y". Без JS-генерации контента/innerHTML/canvas/клонов. JS анимирует по HTML-номерам.

База: article видимы в потоке; rect сразу рисуют 1. IIFE после HTML: scope=document.currentScript?.getRootNode()||document; ищи секцию в scope; init/render сразу, не по load/scroll. Скрытие/sticky только после успешного render; при сбое верни базу. Превью без скролла: этап 1, высота H, без sticky. iframe ≠ редактор. Редактор: все этапы с HTML-номерами, без sticky/эффектов.

Фон linear-gradient(120deg,#DF8B59,#D87E4A 65%), белый текст, Arial. Sticky top:0, высота H=innerHeight (в iframe до 800px), padding:0 64px. Центр: grid 1fr 1fr, gap:96px, max-width:1180px. SVG высотой min(.65H,640px), #FAE9E1; заменяет HTML-номер после init. Этапы в одной grid-ячейке. Фото-круг, cover center, диаметр clamp(112px,18vh,160px)+90px, снизу 28px. Заголовок clamp(36px,4.2vw,64px), 400/1.04, -.055em. Описание через 28px: clamp(16px,1.4vw,19px)/1.5, 34ch. Снизу 36px по центру трек 180×2px: белый .25, белое заполнение слева. Без кнопок/общего заголовка.

Номер|название|описание|путь. Полные src в HTML: https://static.tildacdn.com/+путь.
1|Mixing the Dough|We bring the ingredients together and knead with care. Every batch starts with a smooth, supple dough.|tild6438-3064-4361-a661-366162313139/step-1.jpg
2|Letting It Rise|We give the dough time to rest and rise. Slow fermentation develops its flavor and airy texture.|tild6437-6132-4038-b062-623962393132/step-2.jpg
3|Shaping by Hand|We shape each loaf and pastry by hand. Care goes into every fold, layer, and curve.|tild3262-3462-4133-b432-386435383361/step-3.jpg
4|Baking Until Golden|We bake each batch until the crust turns golden. Crisp on the outside, soft and tender within.|tild6434-3831-4264-a365-343064323664/step-4.jpg
5|Fresh on the Counter|We fill our counter with freshly baked bread and pastries. Come in, take a look, and choose your favorite.|tild3461-3139-4636-a666-366133383635/step-5.jpg

SVG viewBox="0 0 300 436": 24 rect в HTML, 8×3; y=row*55.5, height:47, width:94, x:0/103/206.
1:010/110/010/010/010/010/010/111
2:010/101/001/001/010/100/100/111
3:010/101/001/010/001/001/101/010
4:101/101/101/101/111/001/001/001
5:111/100/100/110/001/001/101/010
В ряду rect: первая/средняя floor(n/2)/последняя активная колонка; дубли перекрываются.

Обратимый скролл: шаг .95H, высота H+.95H*(N-1+.5). p=clamp(-sectionRect.top/(.95H),0,N-1), f=дробная часть. До f=.5 пауза; phase=clamp((f-.5)/.5,0,1). Задержки [.06,0,.09,.15,.1,.04,.12,0]; t=smoothstep((phase-delay)/(1-delay)). Морфинг a→b: stretch=sin(π*t)*abs(b-a)*.64; width=94+stretch; x=clamp(a+(b-a)*t-stretch/2,0,300-width).
f=.55… .74: старый opacity 1→0,Y 0→-20px; .74… .97: новый opacity 0→1,Y 26→0px; smoothstep. Активный с .75, остальные inert/aria-hidden. Прогресс p/(N-1). Без autoplay. Изолируй CSS/JS; пересчёт resize/правок. Reduced-motion: мгновенно.
Скопировать промпт
Код
Вы можете скопировать код и вставить его в вайб блок в раздел код. Подробнее в инструкции.
<!-- Facts block. All editable content is defined in HTML. --> <section id="vff-facts" class="vff-block" data-section-name="Факты" data-scroll-step="0.95" aria-label="Facts"> <div class="vff-stage"> <div class="vff-main"> <figure class="vff-figure" aria-hidden="true"> <!-- Static animation geometry. Edit the numbers inside each fact. --> <svg class="vff-glyph" viewBox="0 0 300 436" preserveAspectRatio="xMidYMid meet"> <g> <rect x="103" y="0" width="94" height="47"></rect> <rect x="103" y="0" width="94" height="47"></rect> <rect x="103" y="0" width="94" height="47"></rect> <rect x="0" y="55.5" width="94" height="47"></rect> <rect x="103" y="55.5" width="94" height="47"></rect> <rect x="103" y="55.5" width="94" height="47"></rect> <rect x="103" y="111" width="94" height="47"></rect> <rect x="103" y="111" width="94" height="47"></rect> <rect x="103" y="111" width="94" height="47"></rect> <rect x="103" y="166.5" width="94" height="47"></rect> <rect x="103" y="166.5" width="94" height="47"></rect> <rect x="103" y="166.5" width="94" height="47"></rect> <rect x="103" y="222" width="94" height="47"></rect> <rect x="103" y="222" width="94" height="47"></rect> <rect x="103" y="222" width="94" height="47"></rect> <rect x="103" y="277.5" width="94" height="47"></rect> <rect x="103" y="277.5" width="94" height="47"></rect> <rect x="103" y="277.5" width="94" height="47"></rect> <rect x="103" y="333" width="94" height="47"></rect> <rect x="103" y="333" width="94" height="47"></rect> <rect x="103" y="333" width="94" height="47"></rect> <rect x="0" y="388.5" width="94" height="47"></rect> <rect x="103" y="388.5" width="94" height="47"></rect> <rect x="206" y="388.5" width="94" height="47"></rect> </g> </svg> </figure> <!-- Duplicate, reorder or remove a complete vff-fact article. --> <!-- Each fact contains an editable digit, image, title and description. --> <!-- The digit remains editable in HTML and is visually hidden on the page. --> <div class="vff-items"> <article class="vff-fact"> <p class="vff-value">1</p> <img class="vff-photo" src="https://static.tildacdn.com/tild6438-3064-4361-a661-366162313139/step-1.jpg" alt="Mixing the Dough" width="900" height="900" loading="eager" decoding="async"> <h2 class="vff-title">Mixing the Dough</h2> <p class="vff-description">We&nbsp;bring the ingredients together and knead with care. Every batch starts with a&nbsp;smooth, supple dough.</p> </article> <article class="vff-fact"> <p class="vff-value">2</p> <img class="vff-photo" src="https://static.tildacdn.com/tild6437-6132-4038-b062-623962393132/step-2.jpg" alt="Letting It Rise" width="900" height="900" loading="eager" decoding="async"> <h2 class="vff-title">Letting It Rise</h2> <p class="vff-description">We&nbsp;give the dough time to&nbsp;rest and rise. Slow fermentation develops its flavor and airy texture.</p> </article> <article class="vff-fact"> <p class="vff-value">3</p> <img class="vff-photo" src="https://static.tildacdn.com/tild3262-3462-4133-b432-386435383361/step-3.jpg" alt="Shaping by Hand" width="900" height="900" loading="eager" decoding="async"> <h2 class="vff-title">Shaping by Hand</h2> <p class="vff-description">We&nbsp;shape each loaf and pastry by&nbsp;hand. Care goes into every fold, layer, and curve.</p> </article> <article class="vff-fact"> <p class="vff-value">4</p> <img class="vff-photo" src="https://static.tildacdn.com/tild6434-3831-4264-a365-343064323664/step-4.jpg" alt="Baking Until Golden" width="900" height="900" loading="eager" decoding="async"> <h2 class="vff-title">Baking Until Golden</h2> <p class="vff-description">We&nbsp;bake each batch until the crust turns golden. Crisp on&nbsp;the outside, soft and tender within.</p> </article> <article class="vff-fact"> <p class="vff-value">5</p> <img class="vff-photo" src="https://static.tildacdn.com/tild3461-3139-4636-a666-366133383635/step-5.jpg" alt="Fresh on the Counter" width="900" height="900" loading="eager" decoding="async"> <h2 class="vff-title">Fresh on the Counter</h2> <p class="vff-description">We&nbsp;fill our counter with freshly baked bread and pastries. Come in, take a&nbsp;look, and choose your favorite.</p> </article> </div> </div> <footer class="vff-footer"> <div class="vff-progress" aria-hidden="true"> <span class="vff-progress-fill"></span> </div> </footer> </div> </section> <style>
.vff-block#vff-facts {
--vff-background: #D87E4A;
--vff-color: #FFFFFF;
--vff-glyph-color: #FAE9E1;
--vff-photo-size: calc(clamp(112px, 18vh, 160px) + 90px);
position: relative;
width: 100%;
overflow: visible;
background: linear-gradient(120deg, #DF8B59 0%, var(--vff-background) 65%);
color: var(--vff-color);
-webkit-font-smoothing: antialiased;
}

.vff-block#vff-facts,
.vff-block#vff-facts * {
box-sizing: border-box;
font-family: Arial, sans-serif;
}

.vff-block#vff-facts[hidden] {
display: none !important;
}

.vff-block#vff-facts .vff-stage {
position: relative;
padding: 48px 64px;
}

.vff-block#vff-facts .vff-footer {
display: flex;
align-items: center;
justify-content: center;
}

.vff-block#vff-facts .vff-main {
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
align-items: center;
gap: 96px;
width: 100%;
max-width: 1180px;
margin: 64px auto;
}

.vff-block#vff-facts .vff-figure {
min-width: 0;
height: min(65vh, 640px);
margin: 0;
}

.vff-block#vff-facts .vff-glyph {
display: block;
width: 100%;
height: 100%;
overflow: visible;
fill: var(--vff-glyph-color);
}

.vff-block#vff-facts .vff-items {
min-width: 0;
}

.vff-block#vff-facts .vff-fact {
margin: 0 0 48px;
}

.vff-block#vff-facts .vff-value {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
border: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
clip-path: inset(50%);
white-space: nowrap;
}

.vff-block#vff-facts .vff-photo {
display: block;
width: var(--vff-photo-size);
height: var(--vff-photo-size);
margin: 0 0 28px;
border-radius: 50%;
object-fit: cover;
object-position: center;
}

.vff-block#vff-facts .vff-photo[hidden],
.vff-block#vff-facts .vff-photo:not([src]),
.vff-block#vff-facts .vff-photo[src=""] {
display: none;
}

.vff-block#vff-facts .vff-title {
margin: 0;
color: inherit;
font-size: clamp(36px, 4.2vw, 64px);
font-weight: 400;
line-height: 1.04;
letter-spacing: -.055em;
text-wrap: balance;
}

.vff-block#vff-facts .vff-description {
max-width: 34ch;
margin: 28px 0 0;
color: inherit;
font-size: clamp(16px, 1.4vw, 19px);
font-weight: 400;
line-height: 1.5;
letter-spacing: -.015em;
}

.vff-block#vff-facts .vff-progress {
width: 180px;
height: 2px;
background: rgba(255, 255, 255, .25);
}

.vff-block#vff-facts .vff-progress-fill {
display: block;
width: 100%;
height: 100%;
background: currentColor;
transform: scaleX(0);
transform-origin: left center;
}

.vff-block#vff-facts[data-vff-running] .vff-stage {
position: sticky;
top: 0;
display: flex;
flex-direction: column;
justify-content: center;
height: var(--vff-viewport, 100vh);
padding: 0 64px;
overflow: hidden;
}

.vff-block#vff-facts[data-vff-running] .vff-figure {
height: calc(var(--vff-viewport, 800px) * .65);
max-height: 640px;
}

.vff-block#vff-facts[data-vff-running] .vff-footer {
position: absolute;
bottom: 36px;
left: 64px;
right: 64px;
}

.vff-block#vff-facts[data-vff-running] .vff-main {
margin: 0 auto;
}

.vff-block#vff-facts[data-vff-running] .vff-items {
display: grid;
}

.vff-block#vff-facts[data-vff-running] .vff-fact {
grid-area: 1 / 1;
align-self: center;
margin: 0;
opacity: 0;
visibility: hidden;
pointer-events: none;
}

.vff-block#vff-facts[data-vff-running]:not([data-vff-ready]) .vff-fact:first-child {
opacity: 1;
visibility: visible;
pointer-events: auto;
transform: translate3d(0, 0, 0);
}

.vff-block#vff-facts[data-vff-count="1"] .vff-footer {
visibility: hidden;
}
</style> <script>
(function () {
'use strict';

var script = document.currentScript;
var scope = script && script.getRootNode
? script.getRootNode()
: document;

function boot() {
scope.querySelectorAll('.vff-block#vff-facts').forEach(init);
}

function init(root) {
var key = '__vffFactsController';

if (root[key]) {
root[key].refresh();
return;
}

var list = root.querySelector('.vff-items');
var figure = root.querySelector('.vff-figure');
var svg = root.querySelector('.vff-glyph');

if (!list || !figure || !svg) return;

var bars = Array.from(svg.querySelectorAll('rect'));

if (bars.length !== 24) return;

var progress = root.querySelector('.vff-progress-fill');

var reduced = window.matchMedia(
'(prefers-reduced-motion: reduce)'
);

var items = [];
var shapes = [];

var step = 1;
var frame = 0;
var refreshFrame = 0;
var activeIndex = -1;

var hold = .5;
var delays = [.06, 0, .09, .15, .1, .04, .12, 0];

// Geometry definitions only.
// Content is read from the existing HTML.
var glyphs = {
'0': ['010','101','101','101','101','101','101','010'],
'1': ['010','110','010','010','010','010','010','111'],
'2': ['010','101','001','001','010','100','100','111'],
'3': ['010','101','001','010','001','001','101','010'],
'4': ['101','101','101','101','111','001','001','001'],
'5': ['111','100','100','110','001','001','101','010'],
'6': ['010','100','100','110','101','101','101','010'],
'7': ['111','001','001','010','010','100','100','100'],
'8': ['010','101','101','010','101','101','101','010'],
'9': ['010','101','101','101','011','001','001','010']
};

function clamp(value, min, max) {
return Math.min(max, Math.max(min, value));
}

function smooth(value) {
value = clamp(value, 0, 1);
return value * value * (3 - 2 * value);
}

function readShape(item) {
var value = item.querySelector('.vff-value');
var digit = value ? value.textContent.trim() : '';

if (
!Object.prototype.hasOwnProperty.call(glyphs, digit)
) {
return null;
}

return glyphs[digit].map(function (row) {
var columns = [];

for (var column = 0; column < 3; column++) {
if (row[column] === '1') {
columns.push(column * 103);
}
}

return [
columns[0],
columns[Math.floor(columns.length / 2)],
columns[columns.length - 1]
];
});
}

function measure() {
// Prevent auto-height preview iframes from inflating the stage.
var viewport = window.innerHeight
|| document.documentElement.clientHeight || 800;
var embedded = window.self !== window.top;
var height = Math.max(1, embedded ? Math.min(viewport, 800) : viewport);

var speed = parseFloat(
root.getAttribute('data-scroll-step')
);

step = height * (
Number.isFinite(speed) && speed > 0
? speed
: .95
);

root.style.setProperty(
'--vff-viewport',
height + 'px'
);

root.style.height = items.length
? (
height + step * (
items.length > 1
? items.length - 1 + hold
: 0
)
) + 'px'
: '0px';
}

function refresh() {
refreshFrame = 0;

items = Array.from(list.children).filter(function (item) {
return item.matches('.vff-fact')
&& item.textContent.trim();
});

shapes = items.map(readShape);
activeIndex = -1;

root.hidden = !items.length;

root.setAttribute(
'data-vff-count',
String(items.length)
);

root.removeAttribute('data-vff-ready');
root.setAttribute('data-vff-running', '');

Array.from(list.children).forEach(function (item) {
if (item.matches('.vff-fact')) {
item.hidden = items.indexOf(item) === -1;
}
});

list.querySelectorAll('.vff-photo').forEach(function (image) {
if (image.complete) {
image.hidden = image.naturalWidth === 0;
}
});

measure();
// Render immediately even when preview animation frames are paused.
draw();
}

function draw() {
frame = 0;

if (!root.isConnected || !items.length) return;

var start = root.getBoundingClientRect().top
+ window.scrollY;

var position = clamp(
(window.scrollY - start) / step,
0,
items.length - 1
);

var from = Math.floor(position);
var to = Math.min(from + 1, items.length - 1);
var fraction = position - from;

var phase = clamp(
(fraction - hold) / (1 - hold),
0,
1
);

var active = fraction >= .75 ? to : from;
var cut = reduced.matches;

var firstShape = shapes[from] || shapes[to];
var nextShape = shapes[to] || shapes[from];

// Invalid or removed values never produce a placeholder digit.
var figureOpacity = cut
? (shapes[active] ? 1 : 0)
: (
(shapes[from] ? 1 : 0) * (1 - phase)
+ (shapes[to] ? 1 : 0) * phase
);

figure.style.opacity = String(figureOpacity);

if (firstShape && nextShape) {
for (var row = 0; row < 8; row++) {
var t = cut
? (active === to ? 1 : 0)
: smooth(
(phase - delays[row])
/ (1 - delays[row])
);

for (var column = 0; column < 3; column++) {
var a = firstShape[row][column];
var b = nextShape[row][column];

var stretch = cut
? 0
: Math.sin(Math.PI * t)
* Math.abs(b - a)
* .64;

var width = 94 + stretch;

var x = clamp(
a + (b - a) * t - stretch / 2,
0,
300 - width
);

var bar = bars[row * 3 + column];

bar.setAttribute('x', x.toFixed(2));
bar.setAttribute('width', width.toFixed(2));
}
}
}

items.forEach(function (item, index) {
var opacity = 0;
var offset = 0;

if (cut) {
opacity = index === active ? 1 : 0;
} else if (from === to && index === from) {
opacity = 1;
} else if (index === from) {
var exit = smooth((fraction - .55) / .19);

opacity = 1 - exit;
offset = -20 * exit;
} else if (index === to) {
var enter = smooth((fraction - .74) / .23);

opacity = enter;
offset = 26 * (1 - enter);
}

item.style.opacity = opacity.toFixed(3);

item.style.visibility = opacity > .001
? 'visible'
: 'hidden';

item.style.transform =
'translate3d(0,' + offset.toFixed(2) + 'px,0)';
});

if (active !== activeIndex) {
items.forEach(function (item, index) {
item.setAttribute(
'aria-hidden',
index === active ? 'false' : 'true'
);

item.toggleAttribute(
'inert',
index !== active
);

item.style.pointerEvents = index === active
? 'auto'
: 'none';
});

activeIndex = active;
}

if (progress) {
progress.style.transform = 'scaleX(' + (
items.length > 1
? position / (items.length - 1)
: 0
) + ')';
}

root.setAttribute('data-vff-ready', '');
}

function requestDraw() {
if (!frame) {
frame = window.requestAnimationFrame(draw);
}
}

function requestRefresh() {
if (!refreshFrame) {
refreshFrame = window.requestAnimationFrame(refresh);
}
}

function resize() {
measure();
requestDraw();
}

function imageState(event) {
var image = event.target;

if (
!image.matches
|| !image.matches('.vff-photo')
) {
return;
}

image.hidden = event.type === 'error';
requestDraw();
}

// No nodes or text are generated by JavaScript.
// Existing HTML edits automatically update the animation.
var observer = new MutationObserver(requestRefresh);

observer.observe(list, {
childList: true,
subtree: true,
characterData: true,
attributes: true,
attributeFilter: ['src', 'srcset']
});

root.addEventListener('load', imageState, true);
root.addEventListener('error', imageState, true);

window.addEventListener('scroll', requestDraw, {
passive: true
});

window.addEventListener('resize', resize);
window.addEventListener('pageshow', resize);

if (reduced.addEventListener) {
reduced.addEventListener('change', requestDraw);
}

root[key] = {
refresh: requestRefresh
};

refresh();

if (document.fonts && document.fonts.ready) {
document.fonts.ready.then(resize);
}
}

boot();

if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', boot, {
once: true
});
}
})();
</script><style data-vb-overrides="true">
.vff-title {
font-size: 52px;
}
</style>
Скопировать код
Что выбрать, промпт или код?
Копируйте промпт, если хотите получить похожий результат, но ввести информацию о своём бизнесе и задать свои требования. Например, изменить кнопки, тексты, цвета, фотографии или другие элементы.
Копируйте код, если хотите получить точно такой же блок. Чтобы его изменить, придётся отредактировать html-код.
Начните создание сайта на Тильде с простой регистрации на платформе
Made on
Tilda