UI-компоненты
Фото до/после с ползунком
Интерактивный блок для сравнения результата до и после. Подходит для барберов, салонов красоты, медицинских услуг, ремонта, дизайна и любых работ, где важно показать результат наглядно.
До / После
Результат видно без лишних объяснений
Пользователь двигает ползунок и сам сравнивает, что изменилось. Такой блок хорошо работает там, где важен визуальный результат.
Ремонт
Барбер
Медицина
Дизайн
<section class="ba-showcase">
<div class="ba-showcase__text">
<span class="ba-showcase__badge">До / После</span>
<h2>Результат видно без лишних объяснений</h2>
<p>
Пользователь двигает ползунок и сам сравнивает, что изменилось.
Такой блок хорошо работает там, где важен визуальный результат.
</p>
<div class="ba-showcase__facts">
<span>Ремонт</span>
<span>Барбер</span>
<span>Медицина</span>
<span>Дизайн</span>
</div>
</div>
<div class="ba-slider" data-before-after>
<div class="ba-slider__image ba-slider__image--before">
<span>До</span>
</div>
<div class="ba-slider__image ba-slider__image--after">
<span>После</span>
</div>
<div class="ba-slider__line"></div>
<button class="ba-slider__handle" type="button" aria-label="Передвинуть сравнение">
<span></span>
</button>
<input class="ba-slider__range" type="range" min="0" max="100" value="50" aria-label="Сравнить до и после">
</div>
</section>
.ba-showcase {
min-height: 640px;
display: grid;
grid-template-columns: 0.8fr 1.2fr;
gap: 34px;
align-items: center;
padding: 46px;
border-radius: 28px;
overflow: hidden;
background:
radial-gradient(circle at 12% 18%, rgba(59, 130, 246, 0.28), transparent 34%),
radial-gradient(circle at 92% 84%, rgba(236, 72, 153, 0.18), transparent 34%),
linear-gradient(135deg, #020617, #0f172a);
}
.ba-showcase__badge {
display: inline-flex;
margin-bottom: 18px;
padding: 8px 13px;
border-radius: 999px;
color: #bfdbfe;
background: rgba(59, 130, 246, 0.16);
border: 1px solid rgba(96, 165, 250, 0.45);
font-size: 13px;
}
.ba-showcase__text h2 {
margin: 0 0 18px;
color: #ffffff;
font-size: clamp(34px, 5vw, 58px);
line-height: 1.02;
letter-spacing: -0.05em;
}
.ba-showcase__text p {
color: #cbd5e1;
font-size: 17px;
line-height: 1.7;
}
.ba-showcase__facts {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-top: 24px;
}
.ba-showcase__facts span {
border: 1px solid #334155;
border-radius: 999px;
padding: 8px 13px;
color: #bfdbfe;
background: rgba(15, 23, 42, 0.7);
}
.ba-slider {
--position: 50%;
position: relative;
min-height: 460px;
overflow: hidden;
border: 1px solid rgba(148, 163, 184, 0.3);
border-radius: 28px;
background: #020617;
box-shadow: 0 30px 90px rgba(2, 6, 23, 0.55);
isolation: isolate;
}
.ba-slider__image {
position: absolute;
inset: 0;
display: grid;
padding: 24px;
}
.ba-slider__image--before {
place-items: end start;
}
.ba-slider__image--after {
place-items: end end;
}
.ba-slider__image--after span {
margin-left: auto;
}
.ba-slider__image span {
position: relative;
z-index: 3;
border-radius: 999px;
padding: 8px 14px;
color: #ffffff;
background: rgba(15, 23, 42, 0.72);
border: 1px solid rgba(255, 255, 255, 0.22);
}
.ba-slider__image--before {
background:
linear-gradient(135deg, rgba(2, 6, 23, 0.12), rgba(2, 6, 23, 0.45)),
repeating-linear-gradient(
45deg,
#334155 0 14px,
#475569 14px 28px
);
}
.ba-slider__image--before::after {
content: "";
position: absolute;
inset: 70px 70px 90px;
border-radius: 30px;
background:
linear-gradient(135deg, rgba(15, 23, 42, 0.88), rgba(30, 41, 59, 0.82));
border: 1px dashed rgba(203, 213, 225, 0.35);
}
.ba-slider__image--after {
z-index: 2;
clip-path: inset(0 0 0 var(--position));
place-items: end end;
background:
radial-gradient(circle at 72% 28%, rgba(255, 255, 255, 0.34), transparent 18%),
linear-gradient(135deg, #1d4ed8, #9333ea);
}
.ba-slider__image--before {
z-index: 1;
}
.ba-slider__image--after::before {
content: "";
position: absolute;
inset: 70px 70px 90px;
border-radius: 30px;
background:
linear-gradient(135deg, rgba(255, 255, 255, 0.20), rgba(255, 255, 255, 0.06));
border: 1px solid rgba(255, 255, 255, 0.26);
box-shadow: 0 24px 90px rgba(37, 99, 235, 0.35);
}
.ba-slider__line {
position: absolute;
top: 0;
bottom: 0;
left: var(--position);
z-index: 5;
width: 2px;
background: rgba(255, 255, 255, 0.92);
transform: translateX(-50%);
box-shadow: 0 0 24px rgba(96, 165, 250, 0.75);
pointer-events: none;
}
.ba-slider__handle {
position: absolute;
top: 50%;
left: var(--position);
z-index: 6;
width: 56px;
height: 56px;
border: 1px solid rgba(255, 255, 255, 0.42);
border-radius: 50%;
background: rgba(15, 23, 42, 0.88);
transform: translate(-50%, -50%);
cursor: grab;
box-shadow: 0 18px 50px rgba(2, 6, 23, 0.55);
}
.ba-slider__handle:active {
cursor: grabbing;
}
.ba-slider__handle span::before,
.ba-slider__handle span::after {
content: "";
position: absolute;
top: 50%;
width: 9px;
height: 9px;
border-top: 2px solid #ffffff;
border-left: 2px solid #ffffff;
}
.ba-slider__handle span::before {
left: 17px;
transform: translateY(-50%) rotate(-45deg);
}
.ba-slider__handle span::after {
right: 17px;
transform: translateY(-50%) rotate(135deg);
}
.ba-slider__range {
position: absolute;
inset: 0;
z-index: 7;
width: 100%;
height: 100%;
opacity: 0;
cursor: ew-resize;
}
.ba-slider.is-moving .ba-slider__handle {
transform: translate(-50%, -50%) scale(1.08);
}
@media (max-width: 768px) {
.ba-showcase {
grid-template-columns: 1fr;
padding: 26px 18px;
}
.ba-slider {
min-height: 360px;
}
.ba-slider__image--before::after,
.ba-slider__image--after::before {
inset: 54px 36px 78px;
}
}
const beforeAfterSlider = document.querySelector("[data-before-after]");
const beforeAfterRange = beforeAfterSlider.querySelector(".ba-slider__range");
function updateBeforeAfter(value) {
beforeAfterSlider.style.setProperty("--position", value + "%");
}
beforeAfterRange.addEventListener("input", function () {
updateBeforeAfter(beforeAfterRange.value);
});
beforeAfterRange.addEventListener("pointerdown", function () {
beforeAfterSlider.classList.add("is-moving");
});
beforeAfterRange.addEventListener("pointerup", function () {
beforeAfterSlider.classList.remove("is-moving");
});
beforeAfterRange.addEventListener("pointercancel", function () {
beforeAfterSlider.classList.remove("is-moving");
});
updateBeforeAfter(beforeAfterRange.value);