How can I change the hover opacity effect of a tex

2019-09-08 23:32发布

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?

2条回答
狗以群分
2楼-- · 2019-09-08 23:57

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');
});
查看更多
唯我独甜
3楼-- · 2019-09-08 23:57

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.

查看更多
登录 后发表回答