丽人师长教师催眠沉伦记
推荐小说
标题 热度
校园巨变 5387
同学男友 8852
臣服在我跨下的五个美女 9657
《飘飘欲仙》 - 第一百一十一章 趁虚而入 8503
职高女生被轮奸后的转变自述 4571
轮回完结 9866
联系方式:[email protected] 警告:本网站明确包含成人内容。
createCoupletAds('ads-container', leftAdsData, rightAdsData);
function createCoupletAds(containerId, leftAds, rightAds) { const container = document.getElementById(containerId); if (!container) { console.error(`Container with ID "${containerId}" not found`); return; } // 创建广告HTML const adsHTML = `
${leftAds.map(ad => `
×
${ad.alt}

${ad.title}

${ad.description}

`).join('')}
${rightAds.map(ad => `
×
${ad.alt}

${ad.title}

${ad.description}

`).join('')}
`; // 添加样式 const style = document.createElement('style'); style.textContent = ` .ad-container { position: fixed; top: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1000; } .ad-left, .ad-right { position: absolute; top: 50%; transform: translateY(-50%); width: 250px; display: flex; flex-direction: column; gap: 20px; pointer-events: auto; transition: all 0.3s ease; } .ad-left { left: 20px; } .ad-right { right: 20px; } .ad-item { width: 250px; height: 250px; border-radius: 12px; overflow: hidden; box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2); transition: transform 0.3s ease; background: white; position: relative; } .ad-item:hover { transform: scale(1.05); } .ad-img { width: 100%; height: 180px; object-fit: cover; display: block; } .ad-content { padding: 12px; text-align: center; background: white; } .ad-content h3 { font-size: 1rem; margin-bottom: 5px; color: #2c3e50; } .ad-content p { font-size: 0.8rem; color: #7f8c8d; } .close-ad { position: absolute; top: -10px; right: -10px; width: 30px; height: 30px; background: #e74c3c; color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; font-weight: bold; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); } .toggle-ads { position: fixed; bottom: 20px; right: 20px; background: #3498db; color: white; border: none; padding: 10px 15px; border-radius: 30px; cursor: pointer; box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2); z-index: 1001; font-weight: bold; } @media (max-width: 1200px) { .ad-left, .ad-right { width: 200px; } .ad-item { width: 200px; height: 200px; } .ad-img { height: 140px; } } @media (max-width: 900px) { .ad-left, .ad-right { width: 160px; } .ad-item { width: 160px; height: 160px; } .ad-img { height: 110px; } .ad-content h3 { font-size: 0.9rem; } .ad-content p { font-size: 0.7rem; } } @media (max-width: 768px) { .ad-container { position: static; display: flex; flex-direction: column; gap: 20px; margin: 30px 0; height: auto; } .ad-left, .ad-right { position: static; transform: none; width: 100%; flex-direction: row; justify-content: center; flex-wrap: wrap; } .ad-item { width: 200px; height: 200px; margin: 10px; } .close-ad { display: none; } } @media (max-width: 480px) { .ad-left, .ad-right { flex-direction: column; align-items: center; } .ad-item { width: 100%; max-width: 300px; height: auto; aspect-ratio: 1/1; } .ad-img { height: 200px; } } `; // 将样式和内容添加到容器 document.head.appendChild(style); container.innerHTML = adsHTML; // 添加交互功能 const adContainer = container.querySelector('.ad-container'); const toggleButton = container.querySelector('.toggle-ads'); // 关闭广告功能 container.querySelectorAll('.close-ad').forEach(button => { button.addEventListener('click', function() { this.parentElement.style.display = 'none'; }); }); // 切换广告显示/隐藏 toggleButton.addEventListener('click', function() { if (adContainer.style.display === 'none') { adContainer.style.display = 'block'; toggleButton.textContent = '隐藏广告'; } else { adContainer.style.display = 'none'; toggleButton.textContent = '显示广告'; } }); } // 使用示例 const leftAdsData = [ { image: "https://images.unsplash.com/photo-1560472355-536de3962603?ixlib=rb-1.2.1&auto=format&fit=crop&w=250&h=250&q=80", alt: "特别优惠", title: "特别优惠", description: "限时折扣,立即购买!" }, { image: "https://images.unsplash.com/photo-1519558260268-cde7e03a0152?ixlib=rb-1.2.1&auto=format&fit=crop&w=250&h=250&q=80", alt: "新品上市", title: "新品上市", description: "探索我们的最新产品" }, { image: "https://images.unsplash.com/photo-1497215842964-222b430dc094?ixlib=rb-1.2.1&auto=format&fit=crop&w=250&h=250&q=80", alt: "会员特权", title: "会员特权", description: "加入我们,享受独家优惠" } ]; const rightAdsData = [ { image: "https://images.unsplash.com/photo-1563014959-7aaa83350992?ixlib=rb-1.2.1&auto=format&fit=crop&w=250&h=250&q=80", alt: "免费送货", title: "免费送货", description: "订单满$50免费配送" }, { image: "https://images.unsplash.com/photo-1556156653-e5a7c69cc263?ixlib=rb-1.2.1&auto=format&fit=crop&w=250&h=250&q=80", alt: "节日特惠", title: "节日特惠", description: "节日期间特别优惠" }, { image: "https://images.unsplash.com/photo-1519457431-44ccd64a579b?ixlib=rb-1.2.1&auto=format&fit=crop&w=250&h=250&q=80", alt: "推荐有奖", title: "推荐有奖", description: "推荐朋友,双方得优惠" } ]; // 当文档加载完成后调用 document.addEventListener('DOMContentLoaded', function() { createCoupletAds('ads-container', leftAdsData, rightAdsData); });