How to remove hover state when the element moves

杀马特。学长 韩版系。学妹 提交于 2019-12-24 22:03:37

问题


I have this example:

<div class="container">
    <div class="bp"></div>
</div>

http://jsfiddle.net/VKwjD/20/

if you hover the same square, his color changes; if you click, the parent size changes so the square move.

My problem is: If you don't move your mouse after the click, the square stays in the hover state... Why ? It's possible to remove this state after the click? without moving the mouse...

Thank you for your help


回答1:


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';
        }
    });        
});


来源:https://stackoverflow.com/questions/21153095/how-to-remove-hover-state-when-the-element-moves

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!