简体   繁体   English

使用CSS过渡创建特定的放大效果

[英]Using css transitions to create a specific zoom-in effect

For visualization of the intended effect, go near the bottom of this site , at the "Catering Services" section, and hover over the three images. 为了可视化预期效果,请转到本网站底部的“餐饮服务”部分,然后将鼠标悬停在这三个图像上。

I want my images, on hover, to zoom-in -- increase in height and width -- while the frame around it shrinks, with overflow:hidden ofcourse. 我希望我的图像在悬停时放大-高度和宽度增加-同时其周围的框架缩小,并带有溢出:当然是隐藏的。

Here's what I have written so far: 到目前为止,这是我写的内容:

<style type="text/css">

  .container {
    float: left;
    width: 50%;
    margin: 0 auto;
  }

  .frame {
    width: 80%;
    height: 50%;
    overflow: hidden;
    -webkit-transition: all 1s ease;
    -moz-transition: all 1s ease;
    -ms-transition: all 1s ease;
    transition: all 1s ease;
  }

  .frame:hover {
    width: 70%;
    height: 45%;
  }

  .frame > img {
    width: 100%;
    -webkit-transition: all 1s ease;
    -moz-transition: all 1s ease;
    -ms-transition: all 1s ease;
    transition: all 1s ease;
  }

  .frame:hover {
    width: 120%;
  }
</style>

<div class="container">
    <div class="frame">
      <img src="http://www.rd.com/wp-content/uploads/sites/2/2016/04/01-cat-wants-to-tell-you-laptop.jpg" alt="Image of a dumb cat sitting on a laptop" title="get off my laptop" />
    </div>
</div>
<!---End of container-->

The height of the frame is shrinking but not the width. 框架的高度在缩小,但宽度在缩小。 Moreover, I want the image to expand on all four sides, and the frame to shrink likewise. 此外,我希望图像在所有四个侧面都扩大,并且框架也要缩小。 Can this be achieved with something other than transitions? 除过渡之外,还能通过其他方式实现吗? Any suggestions or tips on how should I go about solving this? 关于如何解决此问题的任何建议或技巧?

Just animate the img's transform:scale() and you should be all set. 只需为img的transform:scale()设置动画,就应该一切就绪。

Hope it helps! 希望能帮助到你!

  .container { float: left; width: 50%; margin: 0 auto; } .frame { width: 80%; height: 50%; overflow: hidden; -webkit-transition: all 1s ease; -moz-transition: all 1s ease; -ms-transition: all 1s ease; transition: all 1s ease; } .frame:hover { width: 70%; height: 45%; } .frame > img { width: 100%; -webkit-transition: all 1s ease; -moz-transition: all 1s ease; -ms-transition: all 1s ease; transition: all 1s ease; } .frame:hover img { transform: scale(2); } 
 <div class="frame"> <img src="http://www.rd.com/wp-content/uploads/sites/2/2016/04/01-cat-wants-to-tell-you-laptop.jpg" alt="Image of a dumb cat sitting on a laptop" title="get off my laptop" /> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM