我學習jQuery的,我已經寫了旨在當鼠標進入(或葉)一個div
添加(或刪除)一類的簡單腳本。新課程增加了不同的高度,也應該改變輸入的div
的背景顏色和不透明度。更改背景顏色addClass jQuery中
下面的代碼:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Testing jQuery</title>
<style type="text/css">
div {
width: 400px;
height: 300px;
margin: 20px;
float: left;
}
#one {
background-color: red;
}
#two {
background-color: green;
}
#three {
background-color: blue;
}
.change {
height: 150px;
background-color: rgba(0,0,0,0.4);
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
<div id="one"></div>
<div id="two"></div>
<div id="three"></div>
<script type="text/javascript">
$(document).ready(function() {
$("div").mouseenter(function() {
$(this).addClass("change");
});
$("div").mouseleave(function() {
$(this).removeClass("change");
});
});
</script>
</body>
</html>
而高度的變化,有一個在background-color
性能沒有影響。爲什麼?
我已經檢出了.mouseenter()
,.mouseleave()
和.addClass()
API文檔,但找不到特定於此問題的任何內容。
你意識到你可以在CSS中單獨做到這一點,對嗎? –