(function() { // 1. Configuration: Add your image URLs and links here const slidesData = [ { img: 'https://via.placeholder.com/1900x300?text=Ad+1', link: '#' }, { img: 'https://via.placeholder.com/1900x300?text=Ad+2', link: '#' }, { img: 'https://via.placeholder.com/1900x300?text=Ad+3', link: '#' }, { img: 'https://via.placeholder.com/1900x300?text=Ad+4', link: '#' }, { img: 'https://via.placeholder.com/1900x300?text=Ad+5', link: '#' } ]; // 2. Create the Styles const style = document.createElement('style'); style.innerHTML = ` #top-ad-slider { width: 100%; height: 300px; overflow: hidden; position: relative; z-index: 9999; background: #000; } .ad-slide { position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0; transition: opacity 0.8s ease-in-out; background-size: cover; background-position: center; display: block; } .ad-slide.active { opacity: 1; } `; document.head.appendChild(style); // 3. Build the HTML Structure const sliderContainer = document.createElement('div'); sliderContainer.id = 'top-ad-slider'; slidesData.forEach((slide, index) => { const anchor = document.createElement('a'); anchor.href = slide.link; anchor.className = 'ad-slide' + (index === 0 ? ' active' : ''); anchor.style.backgroundImage = url('${slide.img}'); sliderContainer.appendChild(anchor); }); // 4. Inject into the DOM (Top of Body) // Only run on the homepage if (window.location.pathname === '/' || window.location.pathname === '/index.php') { document.body.prepend(sliderContainer); } // 5. Slider Logic let currentSlide = 0; const slides = sliderContainer.querySelectorAll('.ad-slide'); setInterval(() => { slides[currentSlide].classList.remove('active'); currentSlide = (currentSlide + 1) % slides.length; slides[currentSlide].classList.add('active'); }, 5000); // Changes every 5 seconds })();

Tag: British Royals

Translate »