(function() { function lockScroll() { var scrollY = window.scrollY || window.pageYOffset || 0; document.body.dataset.scrollY = scrollY; document.body.style.setProperty('overflow', 'hidden', 'important'); document.body.style.setProperty('position', 'fixed', 'important'); document.body.style.setProperty('top', '-' + scrollY + 'px', 'important'); document.body.style.setProperty('left', '0', 'important'); document.body.style.setProperty('right', '0', 'important'); document.body.style.setProperty('width', '100%', 'important'); document.body.style.setProperty('touch-action', 'none', 'important'); document.body.style.setProperty('overscroll-behavior', 'none', 'important'); document.documentElement.style.setProperty('overflow', 'hidden', 'important'); } function unlockScroll() { var scrollY = parseInt(document.body.dataset.scrollY || '0', 10); document.body.style.removeProperty('overflow'); document.body.style.removeProperty('position'); document.body.style.removeProperty('top'); document.body.style.removeProperty('left'); document.body.style.removeProperty('right'); document.body.style.removeProperty('width'); document.body.style.removeProperty('touch-action'); document.body.style.removeProperty('overscroll-behavior'); document.documentElement.style.removeProperty('overflow'); window.scrollTo(0, scrollY); } function stop(e) { e.preventDefault(); } function bind() { var scrollY = window.scrollY || window.pageYOffset || 0; lockScroll(); var overlay = document.createElement('div'); overlay.style.cssText = 'position:fixed;top:0;left:0;right:0;bottom:0;' + 'background:transparent;z-index:99999;pointer-events:auto;' + 'touch-action:none;overscroll-behavior:none;'; document.body.appendChild(overlay); overlay.addEventListener('wheel', stop, { passive: false }); overlay.addEventListener('touchmove', stop, { passive: false }); overlay.addEventListener('touchstart', stop, { passive: false }); function liftToTop(el, z) { var node = el; while (node && node !== document.documentElement) { var cs = window.getComputedStyle(node); if (cs.position === 'static' || cs.position === '') { node.style.position = 'relative'; } node.style.zIndex = z; node = node.parentElement; } } function bindBtn() { var btn = document.querySelector('.scroll-trigger-btn'); if (!btn) return requestAnimationFrame(bindBtn); liftToTop(btn, 100001); btn.addEventListener('click', function() { overlay.remove(); unlockScroll(); }); } bindBtn(); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', bind); } else { bind(); } })();
Если такое есть — `document.body.style.overflow = 'hidden'` будет перекрыто. ## Самый надёжный способ — `html { overflow: hidden }` + `` через `!important` ```js var html = document.documentElement; var scrollY = window.scrollY || window.pageYOffset || 0; // блокируем на html (Tilda не трогает его стили) html.style.overflow = 'hidden'; html.style.height = '100%'; html.style.touchAction = 'none'; // дублируем на body на случай старых браузеров document.body.style.overflow = 'hidden !important'; document.body.style.touchAction = 'none';
Made on
Tilda