缩放/动画变形的焦点


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>Documenttitle>
  head>
  <style>
    .box {
      width: 100px;
      height: 100px;
      background-color: chartreuse;
      margin: 100px auto;
      transition: 2s;
      /* 变形的原焦点 */
      /* 纵向和横向设置px 默认的情况下是center居中 */
      transform-origin: center;
      /* 如: transform-origin:0px  0px; */
    }
    .box:hover {
      /* 
          对元素进行缩放的函数:
                scaleX( )
                scaleY( )
      */
      /* 横向的伸缩   伸缩不需要用单位 ,伸缩单位是按照自身倍数计算的*/
      /* transform: scaleX(0.5); */
      /* 纵向的伸缩   伸缩不需要用单位 ,伸缩单位是按照自身倍数计算的 */
      /* transform: scaleY(3); */
      /* 向四周放大,按自身倍数放大 */
      transform: scale(2);
    }
    img {
      width: 200px;
      height: 200px;
      transition: 2s;
    }
    .box1 {
      width: 200px;
      height: 200px;
      margin: 0 auto;
      border: 1px solid red;
      /* 指动画的时长 */

      overflow: hidden;
    }
    .box1:hover {
      transform: scale(2);
    }
  style>
  <body>
    <div class="box">div>
    <div class="box1">
      <img src="./img/a.png" alt="" />
    div>
  body>
html>

相关