0

悬停标题时,我还需要图像更改不透明度。现在我只有在悬停图像时才具有不透明度。

在此处查看示例小提琴脚本: //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;}
4

1 回答 1

1

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

$(document).ready(function(){    
  $("img.a, .m-kop").hover(
    function() {
      $("img.a").stop().animate({"opacity": "0"}, "slow");
    },
    function() {
      $("img.a").stop().animate({"opacity": "1"}, "slow");
  }); 
});
于 2013-10-22T12:47:27.137 回答