悬停标题更改不透明度图像时

When hover header change opacity image

本文关键字:图像 不透明度 标题 悬停      更新时间:2023-09-26

当将鼠标悬停在标题上时,我需要图像也改变不透明度。现在,只有将鼠标悬停在图像上时,我才具有不透明度。

请参阅此处的示例小提琴脚本:http://jsfiddle.net/fourroses666/EmsaG/1/

.JS:

$(document).ready(function(){    
  $("img.a").hover(
    function() {
      $(this).stop().animate({"opacity": "0"}, "slow");
    },
    function() {
      $(this).stop().animate({"opacity": "1"}, "slow");
  }); 
});

.HTML:

<div class="m-blok one">
    <h3 class="m-kop"><a href="#">Some header</a></h3>
    <img class="a" src="http://tinyurl.com/732qwvt" width="178" height="78" alt="" style="opacity: 1;">
    <img class="b" src="http://tinyurl.com/nrbj2uk" width="178" height="78" alt="" />
</div>

.CSS

.m-blok{width:178px; height:78px; position:relative; margin:15px;}
img.a {left: 0; position: absolute; top: 0; z-index: 10;}
img.b {left: 0; position: absolute; top: 0;}
.m-kop{position:absolute; z-index:11; color:#fff; margin:55px 0 0 5px; max-width:150px; background:#f00;}
.m-kop a, .m-kop a:hover{color:#fff; text-decoration:none;}

使用您已经完成的操作,您可以这样做:

$(document).ready(function(){    
  $("img.a, .m-kop").hover(
    function() {
      $("img.a").stop().animate({"opacity": "0"}, "slow");
    },
    function() {
      $("img.a").stop().animate({"opacity": "1"}, "slow");
  }); 
});