DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>长悬浮title>
<style>
#hoverBox {
width: 100px;
height: 100px;
border: 1px solid black;
}
#hoverBox:hover {
opacity: 0.999; /* 无关要紧的样式 */
transition: 0s 1s opacity; /* 延时1s */
}
style>
head>
<body>
<div id="hoverBox">div>
body>
html>
<script>
// let timer = null;
// document.querySelector('#hoverBox').addEventListener('mouseover', function (e) {
// timer = setTimeout(() => {
// console.log('停留1s');
// clearTimeout(timer);
// }, 1000)
// })
// document.querySelector('#hoverBox').addEventListener('mouseout', function (e) {
// clearTimeout(timer);
// })
// 过渡结束时间 = 过渡时间 + 延迟时间
document.querySelector('#hoverBox').addEventListener('transitionend', function (e) {
console.log('停留1s');
})
script>
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>长点击title>
<style>
#hoverBox {
width: 100px;
height: 100px;
border: 1px solid black;
}
#hoverBox:hover:active {
opacity: 0.999; /* 无关要紧的样式 */
transition: 0s 3s opacity; /* 延时1s */
}
style>
head>
<body>
<div id="hoverBox">div>
body>
html>
<script>
// let timer = null;
// document.querySelector('#hoverBox').addEventListener('mousedown', function (e) {
// timer = setTimeout(() => {
// console.log('停留3s');
// }, 3000)
// })
// document.querySelector('#hoverBox').addEventListener('mouseup', function (e) {
// clearTimeout(timer)
// })
// 过渡结束时间 = 过渡时间 + 延迟时间
document.querySelector('#hoverBox').addEventListener('transitionend', function (e) {
console.log('停留3s');
})
script>