《CSS动画实用技巧》课程笔记

概述

这是我学习CSS动画实用技巧的课程笔记

常用动画属性——transition

        .change img{
          display:block;
          width:300px;
          height:284px;
          opacity:0;
          -webkit-transform:translate(-100px,-100px);
          -webkit-transition:opacity 1s ease-in-out 0.5s,-webkit-transform 1s ease-in-out;
          transition: opacity 1s ease-in-out 0.5s,transform 1s ease-in-out;
        }
        .change:hover img{
          -webkit-transform:translate(0px,0px);
          opacity:1;
          -webkit-transition: opacity 1s ease-in-out,-webkit-transform 1s ease-in-out .1s;
          transition: opacity 1s ease-in-out,transform 1s ease-in-out .1s;
        }

主要是移动和透明渐变同时进行(有延迟)。

常用动画属性——animation

@keyframes shake-hard {
  2% {
    transform: translate(1px, -2px) rotate(3.5deg); }
  4% {
    transform: translate(-7px, -6px) rotate(3.5deg); }
  6% {
    transform: translate(2px, -6px) rotate(-0.5deg); }
  8% {
    transform: translate(1px, 2px) rotate(2.5deg); }
  10% {
    transform: translate(1px, 7px) rotate(1.5deg); }
  12% {
    transform: translate(0px, 2px) rotate(-0.5deg); }
  14% {
    transform: translate(9px, 2px) rotate(1.5deg); }
  16% {
    transform: translate(-4px, 2px) rotate(3.5deg); }
  18% {
    transform: translate(-9px, 5px) rotate(1.5deg); }
  20% {
    transform: translate(-9px, -8px) rotate(1.5deg); }
  22% {
    transform: translate(-2px, 3px) rotate(-0.5deg); }
  24% {
    transform: translate(3px, 2px) rotate(-2.5deg); }
  26% {
    transform: translate(8px, -7px) rotate(2.5deg); }
  28% {
    transform: translate(-7px, 9px) rotate(-2.5deg); }
  30% {
    transform: translate(-9px, 3px) rotate(-0.5deg); }
  32% {
    transform: translate(-7px, 2px) rotate(3.5deg); }
  34% {
    transform: translate(-1px, -6px) rotate(0.5deg); }
  36% {
    transform: translate(5px, -1px) rotate(3.5deg); }
  38% {
    transform: translate(2px, 6px) rotate(3.5deg); }
  40% {
    transform: translate(-4px, -2px) rotate(-1.5deg); }
  42% {
    transform: translate(1px, -7px) rotate(-2.5deg); }
  44% {
    transform: translate(6px, 7px) rotate(-1.5deg); }
  46% {
    transform: translate(-3px, 6px) rotate(2.5deg); }
  48% {
    transform: translate(-6px, 6px) rotate(2.5deg); }
  50% {
    transform: translate(4px, -6px) rotate(1.5deg); }
  52% {
    transform: translate(-8px, 9px) rotate(-2.5deg); }
  54% {
    transform: translate(-7px, 5px) rotate(-0.5deg); }
  56% {
    transform: translate(-4px, 9px) rotate(2.5deg); }
  58% {
    transform: translate(-6px, -8px) rotate(-0.5deg); }
  60% {
    transform: translate(6px, -9px) rotate(2.5deg); }
  62% {
    transform: translate(2px, 9px) rotate(1.5deg); }
  64% {
    transform: translate(7px, -7px) rotate(1.5deg); }
  66% {
    transform: translate(1px, -3px) rotate(0.5deg); }
  68% {
    transform: translate(9px, -2px) rotate(-0.5deg); }
  70% {
    transform: translate(9px, -3px) rotate(-1.5deg); }
  72% {
    transform: translate(2px, -3px) rotate(-0.5deg); }
  74% {
    transform: translate(6px, -9px) rotate(1.5deg); }
  76% {
    transform: translate(-3px, 6px) rotate(3.5deg); }
  78% {
    transform: translate(1px, 8px) rotate(-0.5deg); }
  80% {
    transform: translate(10px, -2px) rotate(1.5deg); }
  82% {
    transform: translate(-5px, 5px) rotate(3.5deg); }
  84% {
    transform: translate(7px, -5px) rotate(-0.5deg); }
  86% {
    transform: translate(-3px, -7px) rotate(-0.5deg); }
  88% {
    transform: translate(-2px, -1px) rotate(-1.5deg); }
  90% {
    transform: translate(5px, 0px) rotate(-2.5deg); }
  92% {
    transform: translate(10px, -5px) rotate(-0.5deg); }
  94% {
    transform: translate(2px, 9px) rotate(0.5deg); }
  96% {
    transform: translate(4px, -8px) rotate(0.5deg); }
  98% {
    transform: translate(2px, 8px) rotate(-0.5deg); }
  0%, 100% {
    transform: translate(0, 0) rotate(0); } }

其实就是把抖动分隔成一帧帧,然后用keyframes连接起来。

常用动画属性——transform

.cardfan > img{
          position:absolute;
          border:10px solid #fff;
          box-sizing:border-box;
          box-shadow: 4px 4px 3px rgba(0, 0, 0, 0.2);
          -webkit-transform-origin: center 400px;
          transform-origin: center 400px;
          -webkit-transition: -webkit-transform .7s ease;
          transition: transform .7s ease;
        }
        .cardfan img:first-child{
          -webkit-transform:rotate(5deg);
          transform:rotate(5deg);
        }
        .cardfan img:last-child{
          -webkit-transform:rotate(-5deg);
          transform:rotate(-5deg);
        }
        .cardfan:hover img:first-child{
          -webkit-transform:rotate(25deg);
          transform:rotate(25deg);
        }
        .cardfan:hover img:last-child{
          -webkit-transform:rotate(-25deg);
          transform:rotate(-25deg);
        }

其实就是在鼠标接触之后第1,3张图旋转一下。

常用动画属性——animation-delay为负值

.spinner > div{
          display:inline-block;
          width:6px;
          height:100%;
          background:green;
          -webkit-animation: strechdelay 1.2s infinite ease-in-out ;
        }
        .spinner .line2{
          -webkit-animation-delay:-1.1s;
        }
        .spinner .line3{
          -webkit-animation-delay:-1.0s;
        }

        .spinner .line4{
          -webkit-animation-delay:-0.9s;
        }

        .spinner .line5{
          -webkit-animation-delay:-0.8s;
        }/**/
        @-webkit-keyframes strechdelay{
          0%,40%,100%{
            -webkit-transform:scaleY(.4);
          }
          20%{
            -webkit-transform:scaleY(1);
          }
        }

比如:animation-delay为-2s,效果是使动画马上开始,但跳过 2 秒进入动画。

常用动画属性——妙用border颜色

.spinner{
          width:10em;
          height:10em;
          border-radius:100%;
          margin:100px auto;
          border:1.1em solid rgba(255,255,255,.2);
          border-left-color:#fff;
        }

主要是先让一个边框颜色不同,然后让它旋转。

常用动画属性——巧用border宽度

.image-layer:before {
          content: '';
          position: absolute;
          top: 0;
          right: 0;
          border-style: solid;
          border-width: 0;
          border-color: rgba(0,0,0,0.2) #fff;
          border-radius: 0 0 0 4px;
          box-shadow: 0 1px 1px rgba(0,0,0,0.3), -1px 1px 1px rgba(0,0,0,0.2);
          -webkit-transition: all 0.4s ease-out;
          transition:all 0.4s ease-out;
        }

        .image-layer:hover:before{
          border-right-width:80px;
          border-bottom-width:80px;
        }

        .paper-flip.folded .image-layer:before{
          border-right-width:1000px;
          border-bottom-width:600px;
        }

利用宽度做成折角效果。翻页效果有点看不懂。

常用动画属性——实现运动动画

.stage{
          width:120px;
          height:auto;
          margin:0 auto;
          position:relative;
          -webkit-transform-origin:center top;
          -webkit-transform:rotate(-30deg);
          -webkit-animation:sway 2.2s infinite alternate ease-in-out;
        }
        .watch{
          width:100%;
          height:auto;
        }
        .seconds{
          position:absolute;
          width:8%;
          height:auto;
          bottom:11.5%;
          left:45.5%;
          -webkit-transform-origin:center 72.4%;
          -webkit-animation:second 60s infinite linear;
        }
        @-webkit-keyframes second{
          to{
            -webkit-transform:rotate(355deg);
          }
        }
        @-webkit-keyframes sway{
          to{
           -webkit-transform:rotate(30deg);
          }
        }

其实就是利用rotate来进行弧形运动,注意animation-direction:alternatecenter:top

原文地址:https://www.cnblogs.com/yangzhou33/p/8407387.html

时间: 2024-07-28 20:52:26

《CSS动画实用技巧》课程笔记的相关文章

《css定位 position》课程笔记

这是我学习课程css定位 position时做的笔记! 本节内容 html的三种布局方式 position可选参数 z-index 盒子模型和定位的区别 侧边栏导航跟随实例 html的三种布局方式 三种布局:标准流,浮动,定位 两大元素:块级元素(div,h1-6,table,ol,ul,li,p),内联元素(a,span,img,input) position可选参数 static(标准流中正常排列) relative(相对定位) absolute(绝对定位) fixed(脱离正常的文档流,登

div+css定位position详解

div+css定位position详解 1.div+css中的定位position 最主要的两个属性:属性 absolute(绝对定位) relative(相对定位),有他们才造就了div+css布局的多样性,让我们的网页丰富多彩起来. 首先解释relative(相对定位),顾名思义,定位是相对的,那他是相对于什么呢?参照物是什么? 看如下代码: 2 2.预览效果,现在是三个并列的div 3 3.给中间的div增加定位属性:position:relative; top:10px; left:10

web前端css定位position和浮动float

最近做了几个项目:配资公司,ecmal商城等,客户对前台要求都很高.所以,今天来谈谈css的基础,以及核心,定位问题. div.h1或p元素常常被称为块级元素.这意味着这些元素显示为一块内容,即“块框”.与之相反,span和h3等元素称为“行内元素”,这是因为它们的内容显示在行中,即“行内框”. 在这种情况下,这个框称为无名块框,因为它不与专门定义的元素相关联. 块级元素的文本行也会发生类似的情况.假设有一个包含三行文本的段落.每行文本形成一个无名框.无法直接对无名块或行框应用样式,因为没有可以

CSS定位——position、float小结

在CSS使用position属性来指定元素的定位类型,该属性有四种不同类型的定位,分别为static(默认定位).relative(相对定位).absolute(绝对定位)和fixed(固定定位). 要理解以上四种定位,写看一下CSS的文档流(普通流)概念: 除非专门指定,否则所有框(也就是html元素)都在普通流中定位.也就是说,普通流中的元素的位置由元素在 (X)HTML 中的位置决定. 块级框从上到下一个接一个地排列,框之间的垂直距离是由框的垂直外边距计算出来.若某元素的position属

css定位position认识

1.绝对定位(position: absolute) 2.相对定位(position: relative) 3.固定定位(position: fixed) 绝对定位 设置position:absolute(表示绝对定位),作用将元素从文档流中拖出来,然后使用left.right.top.bottom属性相对于其最接近的一个具有定位属性的父包含块进行绝对定位.如果不存在这样的包含块,则相对于body元素,即相对于浏览器窗口. 如下面代码可以实现div元素相对于浏览器窗口向右移动100px,向下移动

CSS定位 position

总体讲:一般使用的是父类用postion:relative属性,子类使用positive:absolute属性 常常使用position用于层的绝对定位,比如我们让一个层位于一个层内具体什么位置,为即可使用position:absolute和position:relative实现. 一.position语法与结构   -   TOP position语法:  position : static absolute relative position参数: static : 无特殊定位,对象遵循HT

【前段开发】10步掌握CSS定位: position static relative absolute float

希望能帮到需要的人,转自:http://www.see-design.com.tw/i/css_position.html 1. position:static 元素的 position 屬性默認值為:static,即該元素出現在文檔的常規位置,不會重新定位. 通常此屬性值可以不設置,除非是要覆蓋之前的定義. #div-1 { position:static; }    .    .    .    .    .    .

css 定位(position)与浮动(float)

html的文档流: 元素排版布局的过程:块级元素:从上至下:行内元素:从右至左. 脱离文档流: 方式:postion和float postion 值 描述 absolute 生成绝对定位的元素,相对于 static 定位以外的第一个父元素进行定位. 元素的位置通过 "left", "top", "right" 以及 "bottom" 属性进行规定. 不可以与float一起用. fixed 生成绝对定位的元素,相对于浏览器窗口进

css定位position(侧边栏导航)

1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8" /> 5 <title></title> 6 <style> 7 html,body,ul,li{ 8 padding:0; 9 margin: 0; 10 } 11 body{ 12 width:100%; 13 height:1700px; 14 } 15 .div{ 16 wid

10步掌握CSS布局定位: position static relative absolute float

无意中看到此文,因作者强调其中避开了浏览器bug/分歧,所以个人认为值得借鉴. 不才仔细看了此文,自觉受益匪浅 ,屡试不爽,佩服作者对css布局的精炼总结,顺便小译了一段, 英文水平有限,且个人通常写写php,对css了解不深却有点兴趣,错误之处还请指正. 个人没有空间,代码中的css文件和js保留了完整路径:http://www.barelyfitz.com/screencast/html-training/css/positioning/ 原文地址:http://www.barelyfitz