js动画

1.transform变形

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>transform变形</title>
    <style type="text/css">
        div{
            width: 100px;
            height: 100px;
            background-color: red;
            margin:50px auto 0;
            transition: all 500ms ease;
        }
        .box1:hover{
            transform: rotate(360deg);
        }
        .box2:hover{
            transform: scale(0.5,0.2);
        }
        .box3:hover{
            transform: skew(0,45deg);
        }
        .box4:hover{
            transform: translate(50px,50px);
        }

    </style>
</head>
<body>
    <div class="box1"></div>
    <div class="box2"></div>
    <div class="box3"></div>
    <div class="box4"></div>
    
</body>
</html>

2. 变形的中心点

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

3. 元素的旋转

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>元素旋转</title>
    <style type="text/css">
        .box{
            width:300px;
            height: 300px;
            background-color: gold;
            margin: 50px auto 0;
            transition: all 500ms ease;
        }
        .box{
            /*transform:rotate(45deg);   默认沿z轴旋转*/
            /*perspective设置透视距离,经验数800px比较符合人眼的透视效果*/
            /*transfor:*/
        }
    </style>
</head>
<body>
    <div class="box"></div>
    
</body>
</html>

4.图片文字的遮罩

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>图片文字的遮罩</title>
    <style type="text/css">
        .img{
            width: 122px;
            height: 122px;
            border: solid 1px black;
            position: relative;
            overflow: hidden;
        }
        .img:hover{

        }
        .pic{
            width: 122px;
            height:122px;
        }
        .pic-info{
            width:122px;
            /*height: 100px;*/
            background-color: rgba(234,234,234,0.5);
            position: absolute;
            left: 0;
            top: 122px;
            transition: all 500ms ease;
        }
        .img:hover .pic-info{
            top: 60px;
        }
        p{
            margin: 5px;
            line-height: 30px;
        }
    </style>
</head>
<body>
    <div class="img">
        <img src="img/拳头.jpg" alt="这是一张拳头的图片" class="pic">
        <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">
        .box{
            width: 300px;
            height: 300px;
            background-color: gold;
            text-align: center;
            line-height: 50px;
            
            font-size: 50px;
            transition: all 500ms ease;
            transform-style: preserve-3d;
            transform:perspective(800px) rotateY(0deg);
            /*设置盒子备件是否可见*/
            backface-visibility: hidden;
        }
        .con{
            width: 300px;
            height: 300px;
            margin: 50px auto 0;
            border:1px solid black;
        }
        .con:hover .box{

        }
    </style>
</head>
<body class="con">
    <div class="box">div元素</div>
    
</body>
</html>

6. 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: width 500ms ease,height 500ms ease 500ms,background-color 500ms ease 1s,border-radius 500ms ease,border-radius 500ms ease 1s;*/
            /*产生动画的位置  动画消耗的时间  运动的曲线  延迟的时间(不写就是不延迟) 用逗号分隔,写下一个*/
            transition: all 500ms ease;
        }
        .box:hover{
            width: 500px;
            height: 300px;
            background-color: #abf;
            border-radius: 50px;   /*圆角*/
        }
    </style>
</head>
<body>
    <div class="box"></div>
    
</body>
</html>

7. 简单的制作了一个 loading 的动态图

图片.png

代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>loading标志</title>
    <style type="text/css">
        .big{
            width: 700px;
            height: 300px;
            border: solid 1px black;
            text-align: center;
            position: relative;
            margin: 50px auto 40px;
        }
        .one{
            display: inline-block;
            margin: 50px auto 40px;
            width: 20px;
            height: 90px;
            margin-right: 30px;
            border-radius: 50px;
            background-color: red;
            animation: loading 1s ease infinite alternate;
            transform: scaleY(1);
        }
        .two{
            background-color: orange;
            animation: loading 1s ease 0.2s infinite alternate;

        }
        .three{
            background-color: yellow;
            animation: loading 1s ease 0.6s infinite alternate;
        }
        .four{
            background-color: green;
            animation: loading 1s ease 0.8s infinite alternate;
        }
        .five{
            background-color: blue;
            animation: loading 1s ease 1s infinite alternate;
        }

        @keyframes loading{
            from{
                transform: scaleY(1);
            }
            to{
                transform: scaleY(0.38);
            }
        }
        p{
            position: absolute;
            top: 180px;
            left: 310px;
        }
        
    </style>
</head>
<body>
    <div class="big">
        
        <div class="one"></div>
        <div class="one two"></div>
        <div class="one three"></div>
        <div class="one four"></div>
        <div class="one five"></div>
        <p>loading……</p>
    </div>
    
</body>
</html>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 前言 又到了炎热的7月,很久没有更新技术文章了,原因是上月月底实习结束,从公司离职。然后最近在弄自己的项目和考驾照...
    大力有话说阅读 12,943评论 4 14
  • 看了很多视频、文章,最后却通通忘记了,别人的知识依旧是别人的,自己却什么都没获得。此系列文章旨在加深自己的印象,因...
    DCbryant阅读 4,057评论 0 2
  • 比较 兼容性 css3 兼容性不好,IE10才开始支持。 js 兼容性好,甚至可以兼容IE6。 性能 css3 在...
    小b侠阅读 4,012评论 0 0
  • 原文地址:→传送门 写在前面 之前学习了CSS animation/setTimeout/setInterval/...
    楼心漫阅读 4,849评论 0 4
  • React+Electron桌面应用开发文章索引 这篇文章继续之前的文章,介绍如何创建弹窗。 MaterialUI...
    张老师Klog阅读 12,002评论 0 3

友情链接更多精彩内容