如何使显示id为“的元素的2个函数setTimeOut”;“混乱”;然后隐藏它,只在主页上运行,这样如果用户转到另一个页面,它就不会再次运行。我知道代码在这里不起作用。它正在与elementor合作开发wordpress网站。非常感谢。
<div id="cursorz">
<div class="message" id="mess">Look at you! You look beautiful today!</div>
</div>
@media only screen and (min-width: 1367px) {
body {cursor:none;}
.message {
width: 20em;
height: 5em;
padding: 10px;
border: 2px solid black;
color: white;
background-color: black;
position: absolute;
top: 2em;
left: 2em;
border-radius: 20px;
text-align: center;
vertical-align: baseline;
transition: all 2s ease;
z-index: 2;
display: none;
}
.show {
display: block;
}
#cursorz {
z-index:1000000;
pointer-events: none;
width: 2rem;
height: 2rem;
will-change: transform;
background: #f1f1f1;
position: absolute;
mix-blend-mode: difference;
border-radius: 50%;
}
}
<script type="text/javascript">
const cursorz = document.getElementById("cursorz");
const moveCursor = event => {
const cursorWidth = cursorz.offsetWidth / 2;
cursorz.style.left = event.pageX - cursorWidth + "px";
cursorz.style.top = event.pageY - cursorWidth + "px";
};
document.addEventListener("mousemove", moveCursor);
setTimeout(function(){
document.getElementById(\'mess\').classList.add(\'show\');
}, 5000);
setTimeout(function(){
document.getElementById(\'mess\').classList.remove(\'show\');
}, 10000);
</script>