<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> #box{width:100px;height:100px;background:pink;} #big{width:200px;height:200px;background:blue;display:none;margin-left:800px;} </style> </head> <body> <div id="box"></div> <div id="big"></div> </body> <script> var box = document.getElementById('box'); var big = document.getElementById('big'); var timmer; box.onmouseover = big.onmouseover = function (){ // console.log('鼠標(biāo)移入') // box.style.background="yellow"; clearTimeout(timmer); big.style.display="block"; } box.onmouseout = big.onmouseout = function(){ // console.log('鼠標(biāo)移除') // box.style.background="pink"; timmer=setTimeout(function(){ big.style.display="none"; },300); } // big.onmouseover = function(){ // big.style.display="block"; // } // big.onmouseout = function(){ // big.style.display="none"; // } </script> </html>
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> #parent{width:300px;height:300px;background:red;} #son{width:100px;height:100px;background:yellow;} </style> </head> <body> <div id="parent"> <div id="son"></div> </div> </body> <script> var parent = document.getElementById('parent'); parent.onmouseenter= function(){ console.log('鼠標(biāo)移入?yún)^(qū)域') } parent.onmouseleave = function(){ console.log('鼠標(biāo)移除區(qū)域') } </script> </html>
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號