Traveller Declaration
this.pauseRotation());
this.$el.addEventListener('mouseleave', () => this.startRotation());
},
startRotation() {
if (this.autoRotate) {
clearInterval(this.timer);
this.timer = setInterval(() => {
this.selectRandomAd();
}, this.rotationInterval);
}
},
pauseRotation() {
clearInterval(this.timer);
},
selectRandomAd() {
// Ensure we don't show the same ad twice in a row
let newAdIndex;
do {
newAdIndex = Math.floor(Math.random() * this.ads.length);
} while (this.selected && this.selected === this.ads[newAdIndex] && this.ads.length > 1);
this.nextImage = this.ads[newAdIndex];
this.desktopImageLoaded = false;
this.mobileImageLoaded = false;
this.preloadImage(this.nextImage.desktopSrc, 'desktop');
this.preloadImage(this.nextImage.mobileSrc, 'mobile');
// Optional: Push analytics event if needed
if (typeof dataLayer !== 'undefined') {
dataLayer.push({
event: 'image_rotation',
adUrl: this.nextImage.url,
adType: 'rotation'
});
}
},
preloadImage(src, type) {
const img = new Image();
img.src = src;
img.onload = () => {
this[type + 'ImageLoaded'] = true;
if (this.desktopImageLoaded && this.mobileImageLoaded) {
this.selected = this.nextImage;
}
};
}
}">
版权说明:
1.版权归本网站或原作者所有;
2.未经本网或原作者允许不得转载本文内容,否则将视为侵权;
3.转载或者引用本文内容请注明来源及原作者;
4.对于不遵守此声明或者其他违法使用本文内容者,本人依法保留追究权等。