html - css3 transition 转换图像

标签 html css

这是演示 1 http://css3.bradshawenterprises.com/cfimg/

我想做的是在此演示中添加缩放或旋转。 所以它应该是:当鼠标悬停在第一个 img 上时,它会消失,第二个 img 会出现,然后会缩放:

   <div id="cf">
     <img class="bottom" src="/images/Windows%20Logo.jpg" />
     <img class="top" src="/images/Turtle.jpg" />
   </div>

   #cf {
      position: relative;
      height: 281px;
      width: 450px;
      margin: 0 auto;
    }
    #cf img {
      position: absolute;
      left: 0;
      -webkit-transition: opacity 1s ease-in-out;
      -moz-transition: opacity 1s ease-in-out;
      -o-transition: opacity 1s ease-in-out;
      transition: opacity 1s ease-in-out;
    }
   #cf img.top:hover {
      opacity: 0;
    }
    #cf img.bottom:hover {
      -o-transform: scale(1.5);
      -moz-transform: scale(1.5);
      -webkit-transform: scale(1.5);
      transform: scale(1.5);
      transition: opacity 1s ease-in-out;
    }

我不知道是否可行,或者我必须使用 js。我想用纯CSS做。 感谢您的宝贵时间!

最佳答案

尝试添加 z-index,像这样:-

#cf {
    position: relative;     
    height: 281px;   
    width: 450px;  
    margin: 0 auto;  
}

#cf img {  
    position: absolute;  
    left: 0;  
    z - index: 1; 
    width: 300px;  
    height: 400px;  
- webkit - transition: opacity 1s ease - in -out;  
 - moz - transition: opacity 1s ease - in -out;  
- o - transition: opacity 1s ease - in -out;  
    transition: opacity 1s ease - in -out;  
}

#cf img.top: hover {  
    opacity: 0;
    z - index: 0;
}
#cf img.bottom: hover {
    z - index: 2;  
 - o - transform: scale(1.5);   
 - moz - transform: scale(1.5);   
 - webkit - transform: scale(1.5);    
    transform: scale(1.5);    
    transition: opacity 1s ease - in -out;   
}

关于html - css3 transition 转换图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18733335/

相关文章:

html - IE 中的错误图像定位

html - DIV 内的 CSS 表格调整大小

jquery - 在 Magnificent Popup 中更改 ID 小对话框名称

html - 使用 overflow-y 滚动 : hidden

html - 为什么我的图像不会扩展到 div 的完整大小?

javascript - 覆盖 Bootstrap 表选定的行背景颜色

html - 如何让 ie8 文本框在包含水印时显示光标?

javascript - jquery 在图像中淡入淡出

javascript - 使用 JS 在 HTML 中操作 SVG

css - 我可以插入背景大小 : cover into the background shorthand?