How can I change the hover opacity effect of a text link when it is clicked?

帅比萌擦擦* 提交于 2019-12-12 00:57:55

问题


How can I unbind the hover opacity effect of a text link when it is clicked?

For instance,

a.test {
    text-decoration:none;
}

a.test:hover {
    text-decoration:none;
    opacity:0.6 !important;
    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=60)"; 
    filter:alpha(opacity=60) !important; 
}

<a href="#" class="test">Click Me</a>

$(".test").click(function(){
   $(this).unbind('mouseenter mouseleave');
   return false;
})

I don't want that opacity hover effect when it is clicked.

Here is the link.

EDIT:

I would prefer a solution without hack classes. Is it possible?


回答1:


here is a solution that adds a class which is used to reset the opacity with css.

a.test:hover {
    opacity:0.6 !important;
    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=60)";
    filter:alpha(opacity=60) !important;
}

a.test.clicked:hover {
    opacity:1 !important;
    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
    filter:alpha(opacity=100) !important;
}


<a href="" class="test">Click Me</a>


$(".test").click(function(){
   return false;
});

$(".test").mousedown(function(){
   $(this).addClass('clicked');
});

$(".test").mouseup(function(){
   $(this).removeClass('clicked');
});



回答2:


If you can't modify the CSS that creates the :hover state, use styles.

$('.test').css({'opacity':'1.0 !important','-ms-filter':'',filter:'none !important'});

Inline style should be a higher priority than CSS styles.



来源:https://stackoverflow.com/questions/7265418/how-can-i-change-the-hover-opacity-effect-of-a-text-link-when-it-is-clicked

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