前端笔记(8)

代码:
1.人物走路动画

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>人物走路动画</title>
    <style type="text/css">
        .box{
            width: 120px;
            height: 182px;
            /*border: 1px solid black;*/
            margin: 50px auto 0;
            overflow: hidden;
            position: relative;
            animation: moving 2s linear infinite;
        }
        .box img{
            position: absolute;
            left: 0;
            top: 0;
            /*steps动画步数,图片有8帧,所以设置为8步*/
            animation: walking 2s steps(16) infinite;
        }
        @keyframes moving{
            0%{
                transform: translate(0px,0px);/*位移*/
            }
            50%{
                transform: translate(200px,0px);
            }
            100%{
                transform: translate(0px,0px);
            }
        }
        @keyframes walking{
            from{
                left: 0px;
            }
            to{
                left: -1920px;
            }
        }
    </style>
</head>
<body>
    <div class="box">
        <img src="../img/88.png" alt="人物走路">
    </div>
</body>
</html>

2.元素旋转

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>元素旋转</title>
    <style type="text/css">
        /*旋转方向判断
        1、X轴向右、Y轴向下、Z轴向屏幕外
        2、让轴向对着自己,顺时针方向就是该轴向的旋转方向*/
        .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轴旋转*/
            /*transform: rotate(45deg);*/
            /*perspective设置透视距离,经验数值800比较符合人眼的透视效果*/
            /*transform: perspective(800px) rotateX(45deg);*/
            transform: perspective(800px) rotateY(-45deg);
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

3.变形中心点

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <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>

4.图片文字遮罩

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>图片文字遮罩</title>
    <style type="text/css">
        .box{
            width: 200px;
            height: 300px;
            margin: 50px auto 0;
            border: 1px solid #000;
            position: relative;
            /*默认文字不可见*/
            overflow: hidden;
        }
        .box img{
            width: 200px;
            height: 300px;
        }
        .box .pic_info{
            width: 200px;
            height: 200px;
            background-color: rgba(0,0,0,0.5);
            color: #fff;
            /*定位使色块在图片正下方*/
            position: absolute;
            left: 0;
            top: 300px;
            transition: all 500ms cubic-bezier(0.470, -0.485, 0.460, 1.435);
        }
        .box:hover .pic_info{
            /*色块上移*/
            top:150px;
        }
        /*间距用p标签的margin,而不直接给.pic_info用padding,因为padding会改变盒子大小*/
        .box .pic_info p{
            margin: 20px;
            line-height: 30px;
        }
    </style>
</head>
<body>
    <div class="box">
        <img src="img/location_bg.jpg" alt="玫瑰花">
        <div class="pic_info">
            <p>图片说明:这是一朵玫瑰花图片说明:这是一朵玫瑰花图片说明:这是一朵玫瑰花图片说明:这是一朵玫瑰花</p>
        </div>
    </div>
</body>
</html>

5.图片翻面

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <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(45deg);初始旋转45度
            */
        }
        .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(10px);初始文字浮起10像素方便查看图片与文字分层的效果*/
            /*初始文字翻转,鼠标移入时才翻正显示*/
            transform: translateZ(2px) rotateY(180deg);
        }
        /*鼠标移入时图片翻为背面隐藏*/
        .con:hover .pic{
            transform: perspective(800px) rotateY(180deg);
        }
        /*鼠标移入时文字翻为正面显示*/
        .con:hover .info{
            transform: perspective(800px) rotateY(0deg);
        }
    </style>
</head>
<body>
    <div class="con">
        <div class="pic">
            <img src="img/location_bg.jpg" alt="玫瑰花">
        </div>
        <div class="info">玫瑰花的文字说明</div>
    </div>
</body>
</html>

6.多帧动画

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>多帧动画</title>
    <style type="text/css">
        .box{
            width: 100px;
            height: 100px;
            background-color: gold;
            margin: 50px auto 0;
            animation: moving 1s ease 1s both;
        }
        @keyframes moving{
            0%{
                /*位移动画*/
                transform: translateY(0px);
                background-color: cyan;
            }
            50%{
                transform: translateY(400px);
                background-color: gold;
                border-radius: 0px;
            }
            100%{
                transform: translateY(0px);
                background-color: red;
                border-radius: 50px;
            }
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

7.背面可见

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>多帧动画</title>
    <style type="text/css">
        .box{
            width: 100px;
            height: 100px;
            background-color: gold;
            margin: 50px auto 0;
            animation: moving 1s ease 1s both;
        }
        @keyframes moving{
            0%{
                /*位移动画*/
                transform: translateY(0px);
                background-color: cyan;
            }
            50%{
                transform: translateY(400px);
                background-color: gold;
                border-radius: 0px;
            }
            100%{
                transform: translateY(0px);
                background-color: red;
                border-radius: 50px;
            }
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

8.animation动画

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>animation动画</title>
    <style type="text/css">
        .box{
            width: 100px;
            height: 100px;
            background-color: gold;
            /*动画名称、时间、曲线、延迟、播放次数、结束后是否返回、动画前后的状态
            infinite不限制次数
            alternate动画结束后返回,返回也算次数
            animation-fill-mode 动画前后的状态
                forwards动画完成保持在最后一帧
                backwards在延迟时间内,在动画显示之前,应用from开始属性值(例如box宽100,from宽200,在延迟1s内显示200)
                both向前和向后填充模式都被应用(例如起始按200,结束停在最后一帧)
            */
            animation: moving 1s ease 1s 5 alternate both;
            /*动画暂停*/
            /*animation-play-state: paused;*/
        }
        .box:hover{
            /*动画运行*/
            /*animation-play-state: running;*/
        }
        /*定义一个动画,名称为moving*/
        @keyframes moving{
            /*初始状态*/
            from{
                width: 200px;
            }
            /*结束状态*/
            to{
                width: 500px;
            }
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

9.css3过渡动画

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>CSS3过渡动画</title>
    <style type="text/css">
        .box{
            width: 100px;
            height: 100px;
            background-color: gold;
            /*在哪产生动画、动画的时间、运动曲线、延迟*/
            /*transition: border-radius 500ms ease,width 500ms ease 500ms,height 500ms ease 1s,background-color 500ms ease 1.5s;*/
            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>
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,544评论 6 501
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,430评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,764评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,193评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,216评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,182评论 1 299
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,063评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,917评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,329评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,543评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,722评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,425评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,019评论 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,671评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,825评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,729评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,614评论 2 353

推荐阅读更多精彩内容

  • 1 CALayer IOS SDK详解之CALayer(一) http://doc.okbase.net/Hell...
    Kevin_Junbaozi阅读 5,148评论 3 23
  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    love2013阅读 2,314评论 0 11
  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    wzhiq896阅读 1,749评论 0 2
  • 看了很多视频、文章,最后却通通忘记了,别人的知识依旧是别人的,自己却什么都没获得。此系列文章旨在加深自己的印象,因...
    DCbryant阅读 1,861评论 0 4
  • 三分之一诸葛亮阅读 139评论 0 0