让我们说你的div1和div2的不透明度都是.40。如何在盘旋时仅为div2制作不透明度1.0?
答案 0 :(得分:2)
.div1,
.div2 {
width: 100px;
height: 100px;
background: blue;
opacity: 0.4;
margin: 10px;
}
.div2:hover {
opacity: 1;
}
<div class="div1"></div>
<div class="div2"></div>
答案 1 :(得分:0)
此处由IrvinDominin在fork上fiddle。最简单的方法是利用不同的类名 - 以这种方式驱动行为。
var rows = document.getElementsByClassName('demo');
for (var i = 0; i < rows.length; i++) {
rows[i].onmouseenter = function (event) {
for (var j = 0; j < rows.length; j++) {
if (rows[j] === this) {
rows[j].className += " other";
}
}
};
rows[i].onmouseleave = function (event) {
var hovers = document.getElementsByClassName('other');
var len = hovers.length;
for (var j = 0; j < len; j++) {
hovers[0].className = hovers[0].className.replace(/\sother(\s|$)/, '');
}
};
}