From b7f9cf49cb65c61cbd25bbd44bc098eec90af2a8 Mon Sep 17 00:00:00 2001 From: dshclm <3321914460@qq.com> Date: Wed, 31 Jul 2024 14:44:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/templates/home/base.html | 67 ++++++++++--------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/ruoyi-admin/src/main/resources/templates/home/base.html b/ruoyi-admin/src/main/resources/templates/home/base.html index 49534f4..2f8cf62 100644 --- a/ruoyi-admin/src/main/resources/templates/home/base.html +++ b/ruoyi-admin/src/main/resources/templates/home/base.html @@ -71,7 +71,7 @@ - 关闭 + 关闭
@@ -523,42 +523,47 @@ $('.myscroll').myScroll({ speed: 30, }); + document.addEventListener('DOMContentLoaded',function(){ + var el = document.querySelector('#ad'); + if (el){ + var styleTop = 0; + var styleLeft = 0; + var verticalFlag = true; + var horizontalFlag = true; + var isMouseOver = false; // 新变量用于跟踪鼠标是否在元素上 - var el = document.querySelector('#ad'); - var styleTop = 0; - var styleLeft = 0; - var verticalFlag = true; - var horizontalFlag = true; - var isMouseOver = false; // 新变量用于跟踪鼠标是否在元素上 + // 设置定时器的函数 + function moveElement() { + if (!isMouseOver) { // 如果鼠标不在元素上,则继续移动 + verticalFlag ? styleTop++ : styleTop--; + horizontalFlag ? styleLeft++ : styleLeft--; - // 设置定时器的函数 - 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); - (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'; - } - } + el.style.top = styleTop +'px'; + el.style.left = styleLeft + 'px'; + } + } - setInterval(moveElement, 20); + setInterval(moveElement, 20); - // 添加事件监听器以检测鼠标是否在元素上 - el.addEventListener('mouseover', function () { - isMouseOver = true; - }); + // 添加事件监听器以检测鼠标是否在元素上 + el.addEventListener('mouseover', function () { + isMouseOver = true; + }); - el.addEventListener('mouseout', function () { - isMouseOver = false; - }); - function closeAd(){ - isMouseOver = true; - el.style.display = 'none' - } + el.addEventListener('mouseout', function () { + isMouseOver = false; + }); + } + function closeAd(){ + isMouseOver = true; + el.style.display = 'none' + } + // 绑定关闭广告的按钮 + document.getElementById('closeButton').addEventListener('click', closeAd); + }) document.addEventListener('DOMContentLoaded', function() { var noticeInner = document.querySelector('.notice__inner'); var noticeItems = Array.from(document.querySelectorAll('.notice__item'));