HTML过渡动画

1、css3过渡动画

<!DOCTYPE html>
<html>
<head>
    <title>css过渡动画</title>
    <style type="text/css">
        .box{
            width: 100px;
            height: 100px;
            background-color: gold;
            /*在哪产生动画、动画的时间、运动曲线、延迟*/
            /*transition: width 150ms ease,height 150ms ease 500ms,background-color 500ms ease 1s,border-radius 500ms ease 1s;*/
            transition: all 500ms ease;
        }
        .box:hover{
            width: 500px;
            height: 300px;
            background-color: red;
            border-radius: 50px;
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

2、圆角 阴影 透明度


<!DOCTYPE html>
<html>
<head>
    <title>y圆角、阴影、透明度</title>
    <style type="text/css">
        .box{
            width: 200px;
            height: 200px;
            bord:2px solid #000;
            background-color: gold;
            margin:50px auto 0;
            /*border-top-left-radius: 100px 50px;左上角为椭圆圆角*/
            /*border-top-left-radius: 100px;*/
            /*border-top-right-radius: 100px;左、右上角为正圆圆角*/
            /*border-radius: 40px;曲率半径为40的圆角矩形*/
            /*border-radius: 20%;最大200px,20%既40px*/
            border-radius: 50%;/*正圆*/
        }
        .box1{
            width: 200px;
            height: 40px;
            background-color: gold;
            margin: 100px auto 0;
            /*水平偏移 垂直偏移 羽化大小 扩展大小 颜色*/
            box-shadow: 10px 10px 10px 0px #bfa;
    
        }
        .box2{
            width: 200px;
            height: 40px;
            background-color: gold;
            margin: 100px auto 0;
            /*水平偏移 垂直偏移 羽化大小 扩展大小 颜色 是否内阴影*/
            box-shadow: 0px 0px 20px 2px red inset;
        }
        body{
            background-color: cyan;
        }
        .box3{
            width: 200px;
            height: 200px;
            /*background:url();*/
            background-color: gold;
            margin: 50px auto 0;
            border:2px solid #000;
            border-radius: 50%;
            /*透明度30%,文字也透明了*/
            opacity: 0.3;
            filter: alpha(opacity=30);/*兼容IE*/
            text-align: center;
            line-height: 200px;
        }
        .box4{
            width: 200px;
            height: 200px;
            /*背景色变透明,但文字不会透明*/
            background-color: rgba(255,215,0,0.3);
            margin: 50px auto 0;
            /*边框透明*/
            border:2px solid rgba(0,0,0,0.3);
            border-radius: 50%;
            text-align: center;
            line-height: 200px;
        }
    </style>
</head>
<body>
    <div class="box"></div>
    <div class="box1"></div>
    <div class="box2"></div>
    <div class="box3">床前明月光</div>
    <div class="box4">床前明月光</div>
</body>
</html>

CSS3圆角

  • 设置某一个角的圆角,比如设置左上角的圆角:
    border-top-left-radius:30px 60px;

  • 同时分别设置四个角: border-radius:30px 60px 120px 150px;

  • 设置四个圆角相同:
    border-radius:50%;

CSS3阴影
box-shadow:h-shadow v-shadow blur spread color inset;
分别设置阴影:水平偏移 垂直偏移 羽化大小 扩展大小 颜色 是否内阴影

rgba(新的颜色值表示法)

1、盒子透明度表示法:opacity:0.1;filter:alpha(opacity=10)(兼容IE);
2、rgba(0,0,0,0.1) 前三个数值表示颜色,第四个数值表示颜色的透明度


3、运动曲线

<!DOCTYPE html>
<html>
<head>
    <title>运动曲线</title>
    <style type="text/css">
        div{
            width: 50px;
            height: 50px;
            background-color: gold;
            margin-bottom: 20px;
        }
        div:nth-child(1){
            transition: all 1s linear;
        }
        div:nth-child(2){
            transition: all 1s ease;
        }
        div:nth-child(3){
            transition: all 1s ease-in; 
        }
        div:nth-child(4){
            transition: all 1s ease-ont;
        }
        div:nth-child(5){
            /*开始和结束时慢速*/
            transition: all 1s ease-in-out;
        }
        div:nth-child(6){
            transition: all 1s cubic-bezier(0.470,-0.485,0.460,1.435);
        }
        div:hover{
            width: 1000px;
        }
    </style>
</head>
<body>
    <div>linear</div>
    <div>ease</div>
    <div>ease-in</div>
    <div>ease-out</div>
    <div>ease-in-out</div>
    <div>bezier</div>
</body>
</html>

4、图片文字遮罩

<!DOCTYPE html>
<html>
<head>
    <title>图片文字遮罩</title>
    <style type="text/css">
        .box{
            width: 300px;
            height: 300px;
            margin: 50px auto 0;
            border-right: 1px solid #000;
            position: relative;
            overflow: hidden;
        }
        .box img{
            width: 300px;
            height: 300px;
        }
        .box .pic_info{
            width: 300px;
            height: 300px;
            background-color: rgba(0,0,0,0.5);
            color: #fff;
            position: absolute;
            left: 0;
            top:300px;

        }
        .box:hover .pic_info{
            top:150px;
        }
        .box .pic_info p{
            margin: 30px;
            line-height: 20px;
        }

    </style>
</head>
<body>
    <div class="box">
        <img src="1.jpg">
        <div class="pic_info">
            <p>这是</p>
        </div>
    </div>
</body>
</html>

5、变形

<!DOCTYPE html>
<html>
<head>
    <title>变形</title>
    <style type="text/css">
        .box,.box2,.box3,.box4{
            width: 200px;
            height: 200px;
            background-color: gold;
            margin: 50px auto 0;
            /*位移*/
            /*transform: translate(50px,50px);*/
            /*旋转*/
            transform: all 1s ease;
        }
        .box:hover{
            /*box的动画不会影响到box2*/
            /*位移*/
            transform: translate(50px,50px);
        }
        .box2:hover{
            /*沿z轴旋转360度*/
            transform: rotate(360deg);
        }
        .box3:hover{
            /*缩放*/
            transform: scale(0.5,0.2);
        }
        .box4:hover{
            /*斜切*/
            transform: skew(0,45deg);
        }
    </style>
</head>
<body>
    <div class="box"></div>
    <div class="box2"></div>
    <div class="box3"></div>
    <div class="box4"></div>
    
</body>
</html>

6、元素旋转

<!DOCTYPE html>
<html>
<head>
    <title>元素旋转</title>
    <style type="text/css">
        .box{
            width: 300px;
            height: 300px;
            background-color: gold;
            margin: 50px auto 0;
            transition: all 500ms ease;
            /*设置盒子按3D空间显示*/
            transform-style: preserve-3d;
            transform: perspective(800px) rotateY(0deg);
        }
        .box:hover{
            /*默认沿z轴旋转*/
            /*perspective设置透视距离,经验数值800比较符合人眼的透视效果*/
            /*transfrom:perspective(800px) rotateX(45deg)*/
            transform: perspective(800px) rotateY(-45deg);
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

7、变形中心点

<!DOCTYPE html>
<html>
<head>
    <title>变形中心点</title>
    <style type="text/css">
        div{
            width: 200px;
            height: 200px;
            background-color: gold;
            float: left;
            margin: 30px;
            transition: all 500ms ease;
        }
        div:hover{
            transform: rotate(-90deg);
        }
        div:nth-child(1){
            /*设置变形的中心点*/
            transform-origin: left center;

        }
        div:nth-child(2){
            transform-origin: left top;
        }
        div:nth-child(3){
            transform-origin: 50px 50px;
        }
    </style>
</head>
<body>
    <div></div>
    <div></div>
    <div></div>
</body>
</html>

8、背面可见

<!DOCTYPE html>
<html>
<head>
    <title>背面可见</title>
    <style type="text/css">
        .con{
            width: 300px;
            height: 300px;
            margin: 50px auto 0;
            border:1px solid #000;
        }
        .box{
            width: 300px;
            height: 300px;
            background-color: gold;
            text-align: center;
            line-height: 300px;
            font-size: 50px;
            transition: all 500ms ease;
            /*设置盒子按3d空间显示*/
            transform-style:preserve-3d;
            /*设置透视距离、三维旋转的初始角度*/
            transform: perspective(800px) rotateY(0deg);
            /*设置盒子背面是否可见*/
            backface-visibility: hidden;

        }
        .con:hover .box{
            transform: rotateY(180deg);
        }
    </style>
</head>
<body>
    <div class="con">
        <div class="box">div元素</div>
    </div>
</body>
</html>

9、图片翻面

<!DOCTYPE html>
<html>
<head>
    <title>图片翻面</title>
    <style type="text/css">
        .con{
            width: 300px;
            height: 272px;
            margin: 100px auto 0;
            position: relative;
            /*transform-style: preserve-3d;*/
            /*transform: perspective(800px) rotateY(0deg);*/

        }
        .pic, .info{
            width: 300px;
            height: 272px;
            position: absolute;
            left: 0;
            top:0;
            /*图片和文字背面不可见,文字初始已翻转,所以隐藏露出底层图片*/
            backface-visibility: hidden;
            transform-style: preserve-3d;
            transform: perspective(800px) rotateY(0deg);
            transition: all 500ms ease;
        }
        .info{
            background-color: gold;
            text-align: center;
            line-height: 272px;
            transform: translateZ(2px) rotateY(180deg);
        }
        /*鼠标移入时图片翻为背面隐藏*/
        .con:hover .pic{
            transform: perspective(800px) rotaeY(180deg);
        }
        /*将鼠标移入时文字翻为正面显示*/
        .con:hover .info{
            transform: perspective(800px) rotateY(0deg);
        }
    </style>
</head>
<body>
    <div class="con">
        <div class="pic">
            <img src="by.jpg" alt="">
            
        </div>
        <div class="info">这是</div>
    </div>
</body>
</html>

10、inimation动画

<!DOCTYPE html>
<html>
<head>
    <title>animation动画</title>
    <style type="text/css">
        .box{
            width: 100px;
            height: 100px;
            background-color: gold;
            /*名称 时间 曲线 延迟 动画次数 返回 起始和结束的状态*/
            animation: moving 1s ease 1s 5 alternate both;
            /*动画暂停*/
            /*animation-play-state: paused;*/
        }
        .box:hover{
            /*动画运行*/
            /*animation-play-state: running;*/
        }
        /*定义一个动画,名称为moving*/
        @keyframes moving{
            /*初始状态*/
            from{
                width: 100px;
            }
            /*结束状态*/
            to{
                width: 500px;
            }
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

CSS3 animation动画

1、@keyframes 定义关键帧动画
2、animation-name 动画名称
3、animation-duration 动画时间
4、animation-timing-function 动画曲线

  • linear 匀速

  • ease 开始和结束慢速

  • ease-in 开始是慢速

  • ease-out 结束时慢速

  • ease-in-out 开始和结束时慢速

  • steps 动画步数
    5、animation-delay 动画延迟
    6、animation-iteration-count 动画播放次数 n|infinite
    7、animation-direction

  • normal 默认动画结束不返回

  • Alternate 动画结束后返回
    8、animation-play-state 动画状态

  • paused 停止

  • running 运动
    9、animation-fill-mode 动画前后的状态

  • none 不改变默认行为

  • forwards 当动画完成后,保持最后一个属性值(在最后一个关键帧中定义)

  • backwards 在 animation-delay 所指定的一段时间内,在动画显示之前,应用开始属性值(在第一个关键帧中定义)

  • both 向前和向后填充模式都被应用
    10、animation:name duration timing-function delay iteration-count direction;同时设置多个属性


11、animation人物走路动画

<!DOCTYPE html>
<html>
<head>
    <title>人物走路动画</title>
    <style type="text/css">
        .box{
            width: 100px;
            height: 200px;
            border:1px solid #000;
            margin: 50px auto 0;
            overflow: hidden;
            position: relative;
            
        }
        .box img{
            position: absolute;
            left: 0;
            top:0;
            /*steps动画步数,图片有8帧,所以设置为8步*/
            animation: walking 1s steps(8) infinite;
        }
        @keyframes walking{
            from{
                left: 0px

            }
            to{
                left: -960px;
            }
        }
    </style>
</head>
<body>
    <div class="box">
        <img src="" alt="">
    </div>
</body>
</html>

12、浏览器前缀

<!DOCTYPE html>
<html>
<head>
    <title>浏览器前缀</title>
    <link rel="stylesheet" type="text/css" href="">
</head>
<body>
    <div class="box"></div>
</body>
</html>

CSS浏览器前缀

浏览器样式前缀

为了让CSS3样式兼容,需要将某些样式加上浏览器前缀:

-ms- 兼容IE浏览器
-moz- 兼容firefox
-o- 兼容opera
-webkit- 兼容chrome 和 safari

自动添加浏览器前缀

目前的状况是,有些CSS3属性需要加前缀,有些不需要加,有些只需要加一部分,这些加前缀的工作可以交给插件来完成,比如安装: autoprefixer

Sublime text 中安装 autoprefixer 执行 preferences/key Bindings-Users 设置快捷键 { "keys": ["ctrl+alt+x"], "command": "autoprefixer" } 通过此工具可以按照最新的前缀使用情况给样式自动加前缀。


13、loading动画

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>多帧动画</title>
    <style type="text/css">
        .box{
            width:400px;
            height:250px;
            border:1px solid #000;
            margin:200px auto 0;
        }

        .box p{
            text-align:center;
            width:100%;
            float:left;
            margin:0;
            padding:0;
        }

        .box div{
            width:50px;
            height:100px;
            float:left;
            background-color:gold;
            margin:15px;
            margin-top: 20px; 
            border-radius:10px;
            margin-top: 40px;
        }

        .box div:nth-child(1){
            background-color:gold;
            animation:loading 200ms ease 0s infinite alternate;
        }

        .box div:nth-child(2){
            background-color:gold;
            animation:loading 200ms ease 50ms infinite alternate;
        }

        .box div:nth-child(3){
            background-color:gold;
            animation:loading 200ms ease 100ms infinite alternate;
        }

        .box div:nth-child(4){
            background-color:gold;
            animation:loading 200ms ease 150ms infinite alternate;
        }

        .box div:nth-child(5){
            background-color:gold;
            animation:loading 200ms ease 200ms infinite alternate;
        }
        
        @keyframes loading{
            from{
                 transform:scaleY(1.4);
            }

            to{
                 transform:scaleY(0.7);
            }
        }
    </style>
</head>
<body>
    <div class="box">
        <div class=""></div>
        <div class=""></div>
        <div class=""></div>
        <div class=""></div>
        <div class=""></div>
        <p>loading...</p>
    </div>
</body>
</html>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 196,099评论 5 462
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 82,473评论 2 373
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 143,229评论 0 325
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,570评论 1 267
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,427评论 5 358
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,335评论 1 273
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,737评论 3 386
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,392评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,693评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,730评论 2 312
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,512评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,349评论 3 314
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,750评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,017评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,290评论 1 251
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,706评论 2 342
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,904评论 2 335

推荐阅读更多精彩内容

  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    love2013阅读 2,299评论 0 11
  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    wzhiq896阅读 1,723评论 0 2
  • 1、属性选择器:id选择器 # 通过id 来选择类名选择器 . 通过类名来选择属性选择器 ...
    Yuann阅读 1,610评论 0 7
  • CSS参考手册 一、初识CSS3 1.1 CSS是什么 CSS3在CSS2.1的基础上增加了很多强大的新功能。目前...
    没汁帅阅读 3,537评论 1 13
  • 郭富城主演的阿胜是一个没有读过多少书,连字都不会写的厨师,因为烂赌,欠了一屁股债,每天被各种催债。 一天,妻子送儿...
    把酒听风阅读 559评论 0 0