Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
211 changes: 211 additions & 0 deletions demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Footer Slide Demo</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
font-family: Arial, sans-serif;
line-height: 1.6;
}

.content {
min-height: 200vh;
padding: 2rem;
background: linear-gradient(45deg, #f0f0f0, #e0e0e0);
}

.section {
margin-bottom: 2rem;
padding: 2rem;
background: white;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.footer-wrapper {
background: #333;
color: white;
padding: 3rem 2rem;
text-align: center;
min-height: 300px;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}

.footer-content h2 {
margin-bottom: 1rem;
font-size: 2rem;
}

.footer-content p {
font-size: 1.1rem;
opacity: 0.8;
}

/* Стили для кнопок переключения */
.controls {
position: fixed;
top: 20px;
right: 20px;
z-index: 1000;
background: white;
padding: 1rem;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.controls button {
display: block;
width: 100%;
margin-bottom: 0.5rem;
padding: 0.5rem 1rem;
border: none;
background: #007bff;
color: white;
border-radius: 4px;
cursor: pointer;
}

.controls button:hover {
background: #0056b3;
}

.controls button:last-child {
margin-bottom: 0;
}
</style>
</head>
<body>
<div class="controls">
<button onclick="initOptimized()">Оптимизированное решение</button>
<button onclick="initModern()">Современное решение</button>
<button onclick="initOriginal()">Оригинальное решение</button>
<button onclick="destroy()">Отключить</button>
</div>

<div class="content">
<div class="section">
<h1>Демонстрация плавного появления футера</h1>
<p>Прокрутите страницу вниз, чтобы увидеть, как футер плавно появляется при скролле.</p>
</div>

<div class="section">
<h2>Преимущества оптимизированного решения:</h2>
<ul>
<li><strong>GPU ускорение</strong> - использование translate3d для аппаратного ускорения</li>
<li><strong>CSS Custom Properties</strong> - минимальные изменения DOM</li>
<li><strong>Passive listeners</strong> - не блокируют скролл</li>
<li><strong>Оптимизированный throttling</strong> - правильное использование requestAnimationFrame</li>
<li><strong>Easing функции</strong> - более естественная анимация</li>
</ul>
</div>

<div class="section">
<h2>Современное решение (CSS Scroll-Driven Animations)</h2>
<p>Для браузеров, поддерживающих новый стандарт CSS Scroll-Driven Animations, используется чисто CSS решение без JavaScript.</p>
</div>

<div class="section">
<h2>Продолжайте скроллить...</h2>
<p>Футер должен появиться плавно без лагов и рывков.</p>
</div>
</div>

<footer class="footer-wrapper">
<div class="footer-content">
<h2>Это футер</h2>
<p>Он плавно появляется при скролле страницы</p>
</div>
</footer>

<script src="footer-slide-optimized.js"></script>
<script>
let currentInstance = null;

function destroy() {
if (currentInstance && currentInstance.destroy) {
currentInstance.destroy();
}
currentInstance = null;

// Очищаем все классы и стили
const footer = document.querySelector('.footer-wrapper');
footer.className = 'footer-wrapper';
footer.style.cssText = '';
}

function initOptimized() {
destroy();
currentInstance = new FooterSlideOptimized();
}

function initModern() {
destroy();
currentInstance = new FooterSlideModern();
}

function initOriginal() {
destroy();
// Ваш оригинальный код (адаптированный)
initFooterSlide();
}

// Адаптированная версия вашего оригинального кода для сравнения
function initFooterSlide() {
const footer = document.querySelector(".footer-wrapper");
const footerHeight = footer.offsetHeight;
const maxShift = footerHeight * 0.8;
let active = false;

footer.style.transform = `translateY(${footerHeight}px)`;
footer.style.position = "relative";
footer.style.transition = "transform 0.3s ease-out";

const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
active = true;
} else {
active = false;
footer.style.transform = `translateY(${footerHeight}px)`;
}
});
}, { threshold: 0 });

observer.observe(footer);

let ticking = false;
window.addEventListener("scroll", () => {
if (!active) return;

if (!ticking) {
window.requestAnimationFrame(() => {
const rect = footer.getBoundingClientRect();
const progress = Math.min(1, (window.innerHeight - rect.top) / footerHeight);

if (progress > 0.8) {
footer.style.transform = `translateY(${footerHeight - maxShift}px)`;
} else {
const shift = footerHeight - progress * maxShift;
footer.style.transform = `translateY(${shift}px)`;
}

ticking = false;
});
ticking = true;
}
});
}
</script>
</body>
</html>
Loading