我这个应该怎么用JS做鼠标经过和离开的效果
发布网友
发布时间:2022-04-30 09:53
我来回答
共1个回答
热心网友
时间:2022-04-20 16:48
用jquery做的话,代码如下:
<title></title>
<script src="../js/jquery-1.7.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$(".logo").mouseenter(function () {
$(".logo_pass").css("display", "block");
}).mouseout(function () {
$(".logo_pass").css("display", "none");
});
});
</script>
</head>
<body>
<div class="logo">111</div>
<div class="logo_pass" style="display:none">222</div>
</body>
</html>
js的话:
给div设置id比较好做
<script type="text/javascript">
window.onload = function () {
var logo = document.getElementById("logo");
logo.onmouseover = function () {
document.getElementById("logo_pass").setAttribute("style", "display:block");
}
logo.onmouseout = function () {
document.getElementById("logo_pass").setAttribute("style", "display:none");
}
}
</script>
</head>
<body>
<div id="logo">111</div>
<div id="logo_pass" style="display:none">222</div>
</body>