简体   繁体   中英

jQuery/JavaScript Function to Change Style Opacity

How do I write a function that, onmouseover;

  • Gets all the 'img' tags in this div
  • Changes style of the image(s) to lower the opacity to 0.5

Thanks in advance!

$('.whatever').on('mouseenter', function() {
    $('img', this).css('opacity', '0.5');
}).on('mouseleave', function() {
    $('img', this).css('opacity', '1');
});

However, you can do the same thing using using pure CSS:

.whatever:hover img { opacity: 0.5; }

Here is a possibility:

$("#yourDiv").bind("mouseover", function(){
    $(this).find("img").css("opacity", "0.5");
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM