<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#id {}
</style>
<script>
window.onload = function() {
var oImg = document.getElementById('ad');
var timer = null;
clearTimeout();
timer = setTimeout(function() {
oImg.style.display = 'none'
}, 2000)
oImg.onmouseover = function() {
clearTimeout(timer);
}
oImg.onmouseout = function() {
timer = setTimeout(function() {
oImg.style.display = 'none'
}, 2000)
}
}
</script>
</head>
<body>
<img id="ad" src="./img/1.png" alt="" style="width: 100px;height: 100px;">
</body>
</html>
運行結果