使用transform属性实现缩放,使用transtion增加动画过渡效果

鼠标悬浮前:

鼠标悬浮后:

实现代码:
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div class="img_box">
    <img src="./images/2.png" alt="">
  </div>
</body>

<style>
  .img_box{
    width: 500px;
    height: 250px;
    overflow: hidden;
  }

  img {
    width: 500px;
    height: 250px;
    transform: scale(1);
    transition: all 1s;
  }

  .img_box:hover img {
    transform: scale(1.2);
    transition: all 1s;
  }
</style>

</html>

宸翰
5 声望1 粉丝

每天进步一点点