@@ -1042,6 +1092,42 @@
$('.myscroll').myScroll({
speed: 30,
});
+
+ let el = document.querySelector('#ad');
+ let styleTop = 0;
+ let styleLeft = 0;
+ let verticalFlag = true;
+ let horizontalFlag = true;
+ let isMouseOver = false; // 新变量用于跟踪鼠标是否在元素上
+
+ // 设置定时器的函数
+ function moveElement() {
+ if (!isMouseOver) { // 如果鼠标不在元素上,则继续移动
+ verticalFlag ? styleTop++ : styleTop--;
+ horizontalFlag ? styleLeft++ : styleLeft--;
+
+ (styleTop <= 0 || styleTop >= window.innerHeight - el.offsetHeight) && (verticalFlag = !verticalFlag);
+ (styleLeft <= 0 || styleLeft >= window.innerWidth - el.offsetWidth) && (horizontalFlag = !horizontalFlag);
+
+ el.style.top = `${styleTop}px`;
+ el.style.left = `${styleLeft}px`;
+ }
+ }
+
+ setInterval(moveElement, 20);
+
+ // 添加事件监听器以检测鼠标是否在元素上
+ el.addEventListener('mouseover', () => {
+ isMouseOver = true;
+ });
+
+ el.addEventListener('mouseout', () => {
+ isMouseOver = false;
+ });
+ function closeAd(){
+ isMouseOver = true;
+ el.style.display = 'none'
+ }