前端CSS3鼠标悬浮过渡缩放效果

2024年04月13日 19:00:22益点益滴602

以下为一个纯css写的图片鼠标悬浮缩放效果,其实基本原理十分简单,我们访问一些网站可以发现他们都会对图片做一些交互效果的处理,当然实现图片过渡效果有很多方式,例如使用JQuery或者一些第三方js动画库,本例仅是展示基本的效果,不对所用知识进行归纳。
代码如下:

  <!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>      <script></script>      <style>          * {              box-sizing: border-box;          }            body {              background-color: rgb(251, 163, 163);          }          /* 长条图样式 */          .containlist {              position: relative;                         margin-top: 100px;              margin-left:10%;                height: 100px;              width: 80%;                overflow: hidden;              border-radius: 30px;              box-shadow: rgb(54, 53, 53) 10px 10px 10px;                       }          .list {                           position: absolute;              width: 100%;              height: 100%;                background-position: center;              background-size: cover;                border-radius: 30px;              transition: 0.5s;                            color: white;              font-weight: bold;              text-align: center;          }                   .list:hover {              transform: scale(1.2);          }      </style>  </head>    <body>           <h1 style="text-align: center;color: white;background-color: black;">效果测试</h1>      <!-- 长条图 -->      <div class="containlist">          <div class="list" style="background-image: url(006.jpg);">              和服の少女          </div>      </div>        <div class="containlist">          <div class="list" style="background-image: url(001.png);">              天空の鏡          </div>      </div>        <div class="containlist">          <div class="list" style="background-image: url(002.png);">              紫の景色          </div>      </div>        <div class="containlist">          <div class="list" style="background-image: url(003.png);">              私は一番可愛いです          </div>      </div>           </body>    </html>

实际效果

git图

图片的样式可以自行进行更改,打造你自己的中二风格。

好了,以上就是前端CSS3鼠标悬浮过渡缩放效果相关的全部内容,希望对您有帮助!

超赞,真给力!嗯,必须鼓励~

打赏 0
账号:mxy310@163.com[复制]
账号:77940140[复制]