我有这个例子:
<div class="container">
<div class="bp"></div>
</div>
如果你将鼠标悬停在同一个方 block 上,他的颜色就会改变;如果单击,父级大小会发生变化,因此方 block 会移动。
我的问题是:如果您在单击后不移动鼠标,则正方形将保持悬停状态...为什么? 单击后可以删除此状态吗?无需移动鼠标...
谢谢你的帮助
最佳答案
HTML:
<div class="container">
<div class="bp" id="bp"></div>
</div>
CSS:
.container {
background: #FF0000;
width: 200px;
height: 200px;
position: relative;
}
.container.hide {
width: 50px;
}
.bp {
background: #00FFFF;
width: 30px;
height:30px;
top:0px;
right:0px;
position:absolute;
cursor: pointer;
}
.bp:hover{
background: #0000FF!important;
}
JavaScript:
$(document).ready(function() {
$('.bp').click(function() {
if($('.container').hasClass('hide')) {
$('.container').removeClass('hide');
var l1 = document.getElementById('bp');
l1.style.background = '#00FFFF';
}
else {
$('.container').addClass('hide');
var l1 = document.getElementById('bp');
l1.style.background = '#0000FF';
}
});
});
关于javascript - 如何在元素移动时移除悬停状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21153095/