H5C3提高(2)

CSS 2D转换

转换(transform)可以实现元素位移(translate)旋转(rotate)缩放(scale)等;

简单理解为变形。

位移

语法:transform:translate(x,y);(translate最大的优点是不会影响其他元素位置)

应用:鼠标指出图片向上,其他盒子位置不变

translate()百分比单位是相对于自身元素来说的

可使盒子水平垂直居中

                          



旋转

transform:rotate(度数)      度数单位deg  正数顺时针转,负数逆时针

默认旋转中心点为元素中心点

缩放

transform:scale(x,y);

注:

transform:scale(1,1);1倍,相当于没放缩

transform:scale(2,2)同transform:scale(2);放大2倍

transform:scale(.5,.5);缩小0.5倍

综合写法

格式:

transform:translate() rotate() scale()..

顺序改变效果(先旋转改变坐标方向)

应把位移放在最前面

分页按钮案例

<!DOCTYPE html>
<html lang="en">

<head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>教务在线</title>
   <link rel="stylesheet" href="初始化表.css">
   <style>
      /*写代码时始终要考虑权重问题!*/

      @font-face {
         font-family: 'icomoon';
         src: url('fonts/icomoon.eot?au9n7q');
         src: url('fonts/icomoon.eot?au9n7q#iefix') format('embedded-opentype'),
            url('fonts/icomoon.ttf?au9n7q') format('truetype'),
            url('fonts/icomoon.woff?au9n7q') format('woff'),
            url('fonts/icomoon.svg?au9n7q#icomoon') format('svg');
         font-weight: normal;
         font-style: normal;
         font-display: block;
      }

      * {
         margin: 0;
         padding: 0;
         box-sizing: border-box;
      }

      ul {
         margin: 0 auto;
         width: 290px;
         height: 40px;
      }

      li {
         width: 30px;
         height: 30px;
         border: 1px solid red;
         text-align: center;
         line-height: 30px;
         margin: 5px;
         border-radius: 50%;
         float: left;
         transition: all 1s;
         cursor: pointer;
      }

      li:hover {
       transform: scale(2,2);/*其放缩不会影响其他元素位置*/

      }
      .clearfix::after {
         content: '';
         display: block;
         height: 0;
         visibility: hidden;
         clear:both;
      }
   </style>

</head>

<body>
   <ul class="clearfix">
      <li>1</li>
      <li>2</li>
      <li>3</li>
      <li>4</li>
      <li>5</li>
      <li>6</li>
      <li>7</li>
   </ul>
</body>

</html>

CSS3动画基本使用

通过设置多个节点精确控制一个或多个动画,实现复杂动画效果

与过渡相比,动画可以实现更多变化、连续自动播放和控制,

制作动画分两步:

先定义动画

再调用动画

用keyframes定义动画(0%为初状态,100%为末状态)

调用:

打开浏览器自动产生动画向右移动

动画序列

0%为开始,100%为结束,期间可以有任意多个

多设几个节点可以实现环绕效果:

<!DOCTYPE html>
<html lang="en">

<head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>!</title>
   <link rel="stylesheet" href="初始化表.css">
   <style>
      /*写代码时始终要考虑权重问题!*/

      @font-face {
         font-family: 'icomoon';
         src: url('fonts/icomoon.eot?au9n7q');
         src: url('fonts/icomoon.eot?au9n7q#iefix') format('embedded-opentype'),
            url('fonts/icomoon.ttf?au9n7q') format('truetype'),
            url('fonts/icomoon.woff?au9n7q') format('woff'),
            url('fonts/icomoon.svg?au9n7q#icomoon') format('svg');
         font-weight: normal;
         font-style: normal;
         font-display: block;
      }

      * {
         margin: 0;
         padding: 0;
         box-sizing: border-box;
      }

      @keyframes move {
         0% {
            transform: translate(0,0);

         }

         25% {
            transform: translate(1000px,0);
         }

         50% {
            transform: translate(1000px,500px);
         }

         75% {
            transform: translate(0,500px);
         }

         100% {
            transform: translate(0,0);
         }
      }

      div {
         width: 200px;
         height: 200px;
         background-color: aqua;
         /*调用动画*/
         animation-name: move;
            /*动画名称*/
         
         /*持续时间*/
         animation-duration: 2s;
      }
   </style>

</head>

<body>
   <div></div>
</body>

</html>

常见属性:

animation-delay:何时开始

animation-iteration-count:播放次数(infinite是无限重复)

animation-direction:是否逆向播放(alternate为逆向);使动画更连贯

animation-fill-mode:是否返回起始状态保持是forward  返回起始是backward

animation-play-state:running是运行,paused为静止;通常和hover使用鼠标接触时静止

animation-timing-function:运动曲线,默认ease,linear为匀速

综合写法:

animation:动画名称 持续时间 运动曲线 何时开始 播放次数 是否反向 动画起始或结束状态

案例

显示并播放一个脉冲动画

<!DOCTYPE html>
<html lang="en">

<head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>!</title>
   <link rel="stylesheet" href="初始化表.css">
   <style>
      /*写代码时始终要考虑权重问题!*/

      @font-face {
         font-family: 'icomoon';
         src: url('fonts/icomoon.eot?au9n7q');
         src: url('fonts/icomoon.eot?au9n7q#iefix') format('embedded-opentype'),
            url('fonts/icomoon.ttf?au9n7q') format('truetype'),
            url('fonts/icomoon.woff?au9n7q') format('woff'),
            url('fonts/icomoon.svg?au9n7q#icomoon') format('svg');
         font-weight: normal;
         font-style: normal;
         font-display: block;
      }

      * {
         margin: 0;
         padding: 0;
         box-sizing: border-box;
      }

      .map {
         width: 100px;
         height: 100px;
         margin: 100px auto;
         position: relative;
         background-color: rgba(0, 0, 0, .4);
      }

      .dotted {
         position: absolute;
         top: 47px;
         left: 47px;
         width: 6px;
         height: 6px;
         background-color: blue;
         border-radius: 3px;

      }

      .map div[class^="pu"] {
         position: absolute;
         top: 50%;
         left: 50%;
         transform: translate(-50%, -50%);
         width: 6px;
         height: 6px;
         border-radius: 50%;
         box-shadow: 0 0 12px #0190e8;
         animation: pulse 1s linear infinite alternate;
         
      }

      .map div.pulse2
      /*要考虑权重问题*/
         {
         animation-delay: .4s;
      }

      .map div.pulse3
      /*要考虑权重问题*/
         {
         animation-delay: .8s;
      }


      @keyframes pulse {
         0% {}

         70% {
            width: 40px;
            height: 40px;
            opacity: 1;
            /*透明度*/
         }

         100% {
            width: 70px;
            height: 70px;
            opacity: 0;
         }
      }
   </style>

</head>

<body>
   <div class="map">
      <div class="dotted"></div>
      <div class="pulse1"></div>
      <div class="pulse2"></div>
      <div class="pulse3"></div>
   </div>
</body>

</html>

特别地,速度曲线的steps()指定时间函数中间隔数量即步长,是分n步来完成。可以用来做进度条!

CSS 3D转换(了解)

特点:近大远小,物体后面遮挡不可见

三维坐标系

x轴水平向右:右为正值

y轴垂直向下:下为正值

z轴垂直屏幕:向外为正值

3D位移

translate3d(x,y,z);

translateZ需要和透视一起用

格式:transform:translate3d(100px,100px,100px);

3D转换

透视 perspective

透视写在元素父盒子上

perspective的参数是视距,即人眼到屏幕距离

z轴是物体与屏幕的距离,实现近大远小

perspective相当于参照物

3D旋转

transform:rotateX(45deg)沿x轴正方向旋转45度

transform:rotateY(45deg)沿y轴正方向旋转45度

transform:rotateZ(45deg)沿z轴正方向旋转45度

3D呈现

transform-style

控制子元素是否开启三维立体环境

transform-style:flat子元素不开启

transform-style:preserve-3d;开启

代码给父类但影响子盒子

  • 10
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

象更

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值