使用图像不透明度悬停时的缩放效果

时间:2017-04-24 23:32:39

标签: javascript jquery html css css3

JSFIDDLE DEMO

我得到了这个工作图像放大与整个div上的链接,但没有不透明度。我在第14-16行添加此代码的那一刻,它显然停止工作:

  background-color: rgba(0,0,0,0.4);
  width: 100%;
  height: 100%;

HTML

<div class="zoom-group">
 <a class="zoom-link" href="#" >
   <div class="zoom-block">
    <img src="http://placehold.it/250x250" />
    <div class="zoom-text">
      Hello
    </div>
  </div>
 </a>
</div>

CSS:

.zoom-group{
  overflow:hidden;
  border: 1px solid #000000; 
  display: block; 
  position: relative; 
  text-align: center;
  height: 250px;
  width: 250px;
}
.zoom-text {
  position: absolute;
  bottom: 0px;
  left: 0px;
  background-color: rgba(0,0,0,0.4);
  width: 100%;
  height: 100%;
}
.zoom-block img{
  max-width: 100%;
  -webkit-transition: all 1s ease; /* Safari and Chrome */
  -moz-transition: all 1s ease; /* Firefox */
  -ms-transition: all 1s ease; /* IE 9 */
  -o-transition: all 1s ease; /* Opera */
  transition: all 1s ease;
}
.zoom-link {
    display: block;
}
.zoom-block img:hover{
  -webkit-transform:scale(1.25); /* Safari and Chrome */
  -moz-transform:scale(1.25); /* Firefox */
  -ms-transform:scale(1.25); /* IE 9 */
  -o-transform:scale(1.25); /* Opera */
   transform:scale(1.25);
}

我应该如何做这项工作?我确实需要不透明度层和放大功能以及可以点击的整个div。

1 个答案:

答案 0 :(得分:4)

img:hover不能发生叠加DIV的原因 改为定位整个父级而不是遍历图像:

只需将您的最后一句话从 .zoom-block img:hover{ 更改为.zoom-group:hover img{

.zoom-group{
  overflow:hidden;
  border: 1px solid #000000; 
  display: block; 
  position: relative; 
  text-align: center;
  height: 250px;
  width: 250px;
}
.zoom-text {
  position: absolute;
  bottom: 0px;
  left: 0px;
  background-color: rgba(0,0,0,0.4);
  width: 100%;
  height: 100%;
}
.zoom-block img{
  max-width: 100%;
  -webkit-transition: all 1s ease; /* Safari and Chrome */
  -moz-transition: all 1s ease; /* Firefox */
  -ms-transition: all 1s ease; /* IE 9 */
  -o-transition: all 1s ease; /* Opera */
  transition: all 1s ease;
}
.zoom-link {
    display: block;
}
.zoom-group:hover img{  /**/
  -webkit-transform:scale(1.25); /* Safari and Chrome */
  -moz-transform:scale(1.25); /* Firefox */
  -ms-transform:scale(1.25); /* IE 9 */
  -o-transform:scale(1.25); /* Opera */
   transform:scale(1.25);
}
<div class="zoom-group">
 <a class="zoom-link" href="#" >
   <div class="zoom-block">
    <img src="http://placehold.it/250x250" />
    <div class="zoom-text">
      Hello
    </div>
  </div>
 </a>
</div>