Change opacity on hover

这一生的挚爱 提交于 2019-12-05 18:18:29

I added a simple class and this JS to accomplish what you're looking for:

$('.radio').on('mouseover mouseout', 'div[type="radio"]', function(){    
    $(this).siblings().toggleClass('hover');
});

.radio div[type='radio'].hover {
    opacity: 0.5;
}

http://jsfiddle.net/Cx35C/3/

I removed the image-targeted CSS, as its parent opacity will trickle down. Also added in a transition similar to what Gazelle has.

I would like to contribute a pure CSS solution to this

Demo

ul li {
    display: inline-block;
}

ul li img {
    opacity: 1;
    -webkit-transition: opacity .5s;
    -moz-transition: opacity .5s;
    transition: opacity .5s;
}

ul:hover li img {
    opacity: .5;
}

ul:hover li img:hover {
    opacity: 1;
}

I will go step by step to explain this, first of all sorry for making this from scratch, your HTML was killing me, so coming to the explanation, first am making all the li inline, than am using ul li img and setting all images to opacity: 1;, well not required but I did set, later am using transition property for smoothing up the animation. The next selector is ul:hover li img, will simply make images opaque to .5 when you hover over ul this means it will set opaque all the images to .5, and at last we set opacity to 1 when you hover any image by using ul:hover li img:hover

This kind of functionality is better achieved with Javascript. Take a look at this JS Fiddle: http://jsfiddle.net/LgZeB/4/

$('.images a').on('mouseover', function () {
    $('.images a').not(this).addClass('fade');
}).on('mouseout', function() {
    $('.images a').removeClass('fade');
});

With jQuery, I'm able to plug into the "mouseover" and "mouseout" functions of the DOM element. Then I can add or remove the relevant CSS class which sets the opacity attribute.

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