1let isLoaded = false; 2 3document.addEventListener("DOMContentLoaded", () => { 4 initializeStickyAd(); 5}); 6 7window.addEventListener("load", () => { 8 if (!isLoaded) { 9 initializeStickyAd(); 10 } 11}); 12 13function initializeStickyAd() { 14 isLoaded = true; 15 16 // Select the target ad element and sections 17 const adElement = document.querySelector('.dfp_ad.div-gpt-ad-DESKTOP_MPU-1'); 18 const startSection = document.querySelector('.wrap'); 19 const endSection = document.querySelector('.whitepaper'); 20 21 // Ensure all required elements exist 22 if (adElement && startSection && endSection) { 23 // Get the initial positions of the start and end sections 24 const startOffsetTop = startSection.offsetTop; // Distance from the top of the document 25 const endOffsetTop = endSection.offsetTop; // Distance from the top of the document 26 27 // Function to handle scroll events 28 const handleScroll = () => { 29 const scrollTop = window.scrollY || document.documentElement.scrollTop; 30 31 // Check if the startSection has hit the top of the viewport 32 const startSectionHitsTop = scrollTop >= startOffsetTop; 33 34 // Calculate the end range for the sticky behavior 35 const endRange = endOffsetTop - adElement.offsetHeight; 36 37 if (startSectionHitsTop && scrollTop <= endRange) { 38 console.log('add sticky !'); 39 adElement.classList.add('sticky'); 40 } else { 41 console.log('remove sticky !'); 42 adElement.classList.remove('sticky'); 43 } 44 }; 45 46 // Attach the scroll event listener 47 window.addEventListener('scroll', handleScroll); 48 49 // Initial check in case the page is already scrolled 50 handleScroll(); 51 52 // Cleanup on page unload 53 window.addEventListener('beforeunload', () => { 54 window.removeEventListener('scroll', handleScroll); 55 }); 56 } else { 57 console.error('Required elements not found.'); 58 } 59}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.