jQuery/JavaScript 函数来更改样式不透明度

jQuery/JavaScript Function to Change Style Opacity

本文关键字:样式 不透明度 JavaScript 函数 jQuery      更新时间:2023-09-26

我如何编写一个函数,鼠标悬停;

  • 获取此div 中的所有"img"标签
  • 更改图像样式以将不透明度降低到 0.5

提前感谢!

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

但是,您可以使用纯CSS执行相同的操作:

.whatever:hover img { opacity: 0.5; }

这是一种可能性:

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