我昨天问了一个问题,但它离题了,我已经解决了代码以通过悬停实现我想要的目标,但现在我希望每个被点击的 div 都变得透明。我知道的问题是我在 Dreamweaver 而不是 phpstorm 中工作,我不确定我使用的命令是否有效。我的html在这里:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div id="category">
<div class="content">
</div>
<div class="content">
</div>
<div class="content">
</div>
<div class="content">
</div>
<div class="content">
</div>
</div>
<style>
div { background-color: springgreen; }
div { width: 100px; }
div { height: 100px; }
</style>
</body>
<script src="js/main.js"></script>
</html>
和 javascript:
/**
* Created by Mark M. on 3/28/2015.
*
*/
var category = document.getElementById("category");
for (var child = category.firstChild; child != null; child = child.nextSibling) {
if (child.nodeType == 1 && child.className == "content") {
child.onmouseover = function() {
this.style.width = "150px";
this.style.height = "150px"
};
child.onmouseout = function() {
this.style.width = "100px";
this.style.height = "100px"
};
child.onmouseclick= function() {
//disappear
this.style.backgroundColor = "transparent";
}
}}