function mouseSlideIn() {
document.getElementById("box").style =
"background: blue; height: 50px; width: 50px;";
}
function mouseSlideOut() {
setTimeout(function() {
document.getElementById("box").style = "";
document.getElementById("eventDiv").style = "";
}, 2000);
}
body {
background: grey;
margin: 0;
}
#eventDiv {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 90vh;
background: powderblue;
border-radius: 20px;
transition: 0.8s;
transition-timing-function: ease;
}
#box {
position: relative;
background: red;
height: 150px;
width: 150px;
transition: 0.5s;
transition-timing-function: ease;
}
<br>
<center>
<div id="eventDiv" onmouseover="mouseSlideIn()" onmouseout="mouseSlideOut()">
<div id="box"></div>
<!--Above is the red box i.e. inside the main DIV-->
</div>
</center>
id="eventDIV"
(最外层的div)上时,id="box"
必须缩小并改变颜色。id="eventDIV"
上时,id="box"
必须恢复到原来的大小和颜色。2000ms
)。setTimeout
功能的帮助下实现。id="eventDIV"
用完之前将 out悬停在
setTimeout
上,即 2000ms
,它会破坏代码。id="eventDIV"
内,也会执行 mouseSlideOut()
函数,该函数应该在 onmouseout
事件上调用;那是我悬停out.clearTimeout
功能,但它似乎没有帮助。注:
:hover
)。