Skip to content

Instantly share code, notes, and snippets.

@baslie
Last active July 3, 2024 05:11
Show Gist options
  • Save baslie/b8bb596bf85fc38204c072e8327570ee to your computer and use it in GitHub Desktop.
Save baslie/b8bb596bf85fc38204c072e8327570ee to your computer and use it in GitHub Desktop.
SmoothScroll для Тильды с помощью библиотеки Lenis
<!-- *********************************************** -->
<!-- SmoothScroll с помощью библиотеки Lenis -->
<!-- *********************************************** -->
<!-- Более плавный скролл, нежели чем «классический» -->
<!-- *********************************************** -->
<script src="https://unpkg.com/@studio-freight/lenis@1.0.42/dist/lenis.min.js"></script>
<script>
// Классы, в которых скрипт «отваливается» — их нужно исключать принудительно :)
const classesToExclude = [
't706',
't-feed__post-popup',
't-popup',
't-popup_show',
// Добавьте новые классы при необходимости с осторожностью
];
const lenis = new Lenis({
lerp: 0.1,
easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)),
orientation: 'vertical',
gestureOrientation: 'vertical',
smoothWheel: true,
wheelMultiplier: 0.95,
syncTouch: false,
touchMultiplier: 1.1,
infinite: false
});
function raf(time) {
lenis.raf(time);
requestAnimationFrame(raf);
}
requestAnimationFrame(raf);
// Добавляем атрибут data-lenis-prevent к нужным элементам
document.addEventListener('DOMContentLoaded', function() {
classesToExclude.forEach(className => {
document.querySelectorAll(`.${className}`).forEach(element => {
element.setAttribute('data-lenis-prevent', '');
});
});
});
</script>
<style>
html.lenis {
height: auto;
}
.lenis.lenis-smooth {
scroll-behavior: auto;
}
.lenis.lenis-smooth [data-lenis-prevent] {
overscroll-behavior: contain;
}
.lenis.lenis-stopped {
overflow: hidden;
}
.lenis.lenis-scrolling iframe {
pointer-events: none;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment