Chương 8

Tác giả: Lam Tiểu Tịch



Thử đọc

script> document.addEventListener("DOMContentLoaded", function () { // 创建 Banner 主容器 const footerBanner = document.createElement('div'); footerBanner.className = 'footer-banner'; // 工具函数:创建广告框 function createAdBox(href, imgSrc, alt) { const adBox = document.createElement('div'); adBox.className = 'ad-box'; let clicked = false; const link = document.createElement('a'); link.href = href; link.target = '_blank'; link.rel = 'nofollow'; const img = document.createElement('img'); img.src = imgSrc; img.alt = alt; link.appendChild(img); adBox.appendChild(link); const closeBtn = document.createElement('span'); closeBtn.className = 'close-banner'; closeBtn.textContent = '×'; closeBtn.onclick = (e) => { e.stopPropagation(); if (!clicked) { clicked = true; window.open(href, '_blank'); } else { adBox.remove(); } }; adBox.appendChild(closeBtn); return adBox; } // 创建两个广告容器 const bannerContainer1 = document.createElement('div'); bannerContainer1.className = 'f8b-1'; const bannerContainer2 = document.createElement('div'); bannerContainer2.className = 'f8b-2'; // 添加广告内容 bannerContainer1.appendChild(createAdBox( 'https://pk-02.online/novelby', 'http://truyenh.com.co/wp-content/uploads/2025/07/banner-by88-mb-1.gif', 'by88' )); bannerContainer2.appendChild(createAdBox( 'https://pk-02.online/linkvmax', 'http://truyenh.com.co/wp-content/uploads/2025/07/pkbet-mobi-1.gif', 'vmax' )); // 组合并挂载到 body footerBanner.appendChild(bannerContainer1); footerBanner.appendChild(bannerContainer2); document.body.appendChild(footerBanner); // 淡入效果 function fadeIn(element, duration) { element.style.opacity = 0; element.style.display = 'block'; let start = null; function step(timestamp) { if (!start) start = timestamp; const progress = timestamp - start; element.style.opacity = Math.min(progress / duration, 1); if (progress < duration) { requestAnimationFrame(step); } } requestAnimationFrame(step); } // 延迟显示广告 setTimeout(() => { fadeIn(footerBanner, 500); }, 5000); });