|
| 1 | +/** |
| 2 | + * Lightweight Webflow Replacement Script |
| 3 | + * Replaces Webflow animations and interactions with vanilla JS |
| 4 | + * Total size: ~2KB unminified |
| 5 | + */ |
| 6 | + |
| 7 | +(function() { |
| 8 | + 'use strict'; |
| 9 | + |
| 10 | + // ===== FADE-IN ANIMATIONS ===== |
| 11 | + // Replaces Webflow's data-w-id fade-in effects |
| 12 | + |
| 13 | + const fadeInElements = document.querySelectorAll('[data-w-id][style*="opacity:0"], [data-w-id][style*="opacity: 0"]'); |
| 14 | + |
| 15 | + if (fadeInElements.length > 0 && 'IntersectionObserver' in window) { |
| 16 | + const fadeInObserver = new IntersectionObserver((entries) => { |
| 17 | + entries.forEach(entry => { |
| 18 | + if (entry.isIntersecting) { |
| 19 | + const element = entry.target; |
| 20 | + |
| 21 | + // Add fade-in animation |
| 22 | + element.style.transition = 'opacity 0.6s ease-out, transform 0.6s ease-out'; |
| 23 | + element.style.opacity = '1'; |
| 24 | + element.style.transform = 'translateY(0)'; |
| 25 | + |
| 26 | + // Unobserve after animation |
| 27 | + fadeInObserver.unobserve(element); |
| 28 | + } |
| 29 | + }); |
| 30 | + }, { |
| 31 | + threshold: 0.1, |
| 32 | + rootMargin: '0px 0px -50px 0px' |
| 33 | + }); |
| 34 | + |
| 35 | + fadeInElements.forEach(element => { |
| 36 | + // Set initial state |
| 37 | + element.style.opacity = '0'; |
| 38 | + element.style.transform = 'translateY(20px)'; |
| 39 | + fadeInObserver.observe(element); |
| 40 | + }); |
| 41 | + } else if (fadeInElements.length > 0) { |
| 42 | + // Fallback for browsers without IntersectionObserver |
| 43 | + fadeInElements.forEach(element => { |
| 44 | + element.style.opacity = '1'; |
| 45 | + }); |
| 46 | + } |
| 47 | + |
| 48 | + // ===== MODAL/POPUP CLOSE HANDLERS ===== |
| 49 | + // Replaces Webflow's close button functionality |
| 50 | + |
| 51 | + document.addEventListener('click', (e) => { |
| 52 | + const closeButton = e.target.closest('.close-pop-up, [data-w-id*="close"]'); |
| 53 | + if (closeButton) { |
| 54 | + e.preventDefault(); |
| 55 | + |
| 56 | + // Find the closest modal/popup container |
| 57 | + const modal = closeButton.closest('.modal, .popup, [class*="pop-up"]'); |
| 58 | + if (modal) { |
| 59 | + modal.style.transition = 'opacity 0.3s ease-out'; |
| 60 | + modal.style.opacity = '0'; |
| 61 | + |
| 62 | + setTimeout(() => { |
| 63 | + modal.style.display = 'none'; |
| 64 | + }, 300); |
| 65 | + } |
| 66 | + } |
| 67 | + }); |
| 68 | + |
| 69 | + // ===== SCROLL-TRIGGERED ANIMATIONS ===== |
| 70 | + // Additional animations for elements that should animate on scroll |
| 71 | + |
| 72 | + const scrollElements = document.querySelectorAll('.section[data-w-id]'); |
| 73 | + |
| 74 | + if (scrollElements.length > 0 && 'IntersectionObserver' in window) { |
| 75 | + const scrollObserver = new IntersectionObserver((entries) => { |
| 76 | + entries.forEach(entry => { |
| 77 | + if (entry.isIntersecting) { |
| 78 | + entry.target.classList.add('is-visible'); |
| 79 | + scrollObserver.unobserve(entry.target); |
| 80 | + } |
| 81 | + }); |
| 82 | + }, { |
| 83 | + threshold: 0.1, |
| 84 | + rootMargin: '0px 0px -100px 0px' |
| 85 | + }); |
| 86 | + |
| 87 | + scrollElements.forEach(element => { |
| 88 | + scrollObserver.observe(element); |
| 89 | + }); |
| 90 | + } |
| 91 | + |
| 92 | + // ===== UTILITY: Remove unused Webflow attributes ===== |
| 93 | + // Clean up data-wf-* attributes that were used by Webflow CMS |
| 94 | + |
| 95 | + function cleanupWebflowAttributes() { |
| 96 | + const webflowAttrs = ['data-wf-page', 'data-wf-site', 'data-wf-domain', 'data-wf-collection', 'data-wf-item-slug']; |
| 97 | + |
| 98 | + webflowAttrs.forEach(attr => { |
| 99 | + const elements = document.querySelectorAll(`[${attr}]`); |
| 100 | + elements.forEach(el => { |
| 101 | + // Keep for reference but these don't affect functionality |
| 102 | + // Uncomment to remove: el.removeAttribute(attr); |
| 103 | + }); |
| 104 | + }); |
| 105 | + } |
| 106 | + |
| 107 | + // Run cleanup on load |
| 108 | + if (document.readyState === 'loading') { |
| 109 | + document.addEventListener('DOMContentLoaded', cleanupWebflowAttributes); |
| 110 | + } else { |
| 111 | + cleanupWebflowAttributes(); |
| 112 | + } |
| 113 | + |
| 114 | + // ===== DEBUG INFO ===== |
| 115 | + console.log('[Webflow Replacement] Initialized'); |
| 116 | + console.log(` - Fade-in elements: ${fadeInElements.length}`); |
| 117 | + console.log(` - Scroll elements: ${scrollElements.length}`); |
| 118 | + console.log(' - Modal close handlers: active'); |
| 119 | + |
| 120 | +})(); |
0 commit comments