css实现简单的抽奖动画效果和旋转效果,还有春联效果

使用css的animation和transform和transition可以实现简单的图片放大缩小,旋转,位移的效果,由此可以延伸的动画效果还是挺多的,比如图片慢慢放大,图片慢慢旋转并放大,图片慢慢变化位置等等,

抽奖动画效果图

实现的原理也很简单,就是通过使用动画animation和关键动画帧来实现的,可以使用缩放来进行平滑的过渡效果,下面是源码:

html 复制代码
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <div class="center">
            <div>抽奖效果</div>
            <img
                src="https://img-blog.csdnimg.cn/67fc9799ae8e48749e82cf70b179895b.png"
                class="card"
            />
        </div>
        <style>
            .center {
                width: 500px;
                margin: 0 auto;
                text-align: center;
            }

            .card {
                width: 260px;
                height: 400px;
                animation: showImg 3s linear 1;
            }

            @keyframes showImg {
                0% {
                    transform: scale(0.1) rotate(0);
                }

                50% {
                    transform: scale(0.5) rotate(360deg);
                }

                100% {
                    transform: scale(1) rotate(720deg);
                }
            }
        </style>
    </body>
</html>

图片旋转360度并放大

图片由小变大,并以y轴为中心旋转360度后展示:

源代码:

html 复制代码
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <div class="wrap">
            <div>抽奖效果</div>
            <div class="box">
                <img
                    src="https://img-blog.csdnimg.cn/67fc9799ae8e48749e82cf70b179895b.png"
                    class="img"
                />
            </div>
        </div>
        <style>
            * {
                padding: 0;
                margin: 0;
                /* height: 100%; */
                width: 100%;
            }
            .wrap {
                margin: 0 auto;
                padding-top: 100px;
                text-align: center;
            }

            .box {
                width: 300px;
                height: 400px;
                margin: 0 auto;
            }

            .img {
                width: 220px;
                height: 300px;
                transform: rotatey(0deg) scale(0.1);
                /* transform-origin: center; */
                transition: all 3s;
            }

            .wrap:hover .img {
                /* transform: scale(1); */
                transform: rotatey(360deg) scale(1);
                -webkit-transform: rotatey(360deg) scale(1);
                -o-transform: rotatey(360deg) scale(1);
                -moz-transform: rotatey(360deg) scale(1);
                -ms-transform: rotatey(360deg) scale(1);
            }
        </style>
    </body>
</html>

图片慢慢旋转动画

图片慢慢旋转是通过rotate来实现的,并且鼠标放上去之后,会有暂停的效果:下面的动图有卡顿的效果,实际情况非常丝滑

旋转图片的源代码:

html 复制代码
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <div class="wrap">
            <div class="source"></div>
            <div class="avatar"></div>
        </div>
    </body>
    <style>
        body {
            background-color: black;
            padding-top: 100px;
        }

        .wrap {
            margin: 0 auto;
            display: flex;
            flex-direction: row;
            justify-content: center;
            align-items: center;
        }

        .source {
            width: 100px;
            height: 100px;
            margin-right: 20px;
            background-image: url('./assets/ball.png');
            background-position: center;
            background-size: 100% 100%;
            animation: circle 1s linear infinite;
        }

        .avatar {
            width: 100px;
            height: 100px;
            border-radius: 50%;
            background-image: url('https://profile-avatar.csdnimg.cn/f6acd04828d84240afc2739fe039fd49_weixin_44786530.jpg!1');
            background-position: center;
            background-size: 100% 100%;
            animation: circle 2s linear infinite;
        }

        .source:hover {
            animation-play-state: paused;
        }

        .avatar:hover {
            animation-play-state: paused;
        }

        @keyframes circle {
            0% {
                transform: rotate(0deg);
            }
            10% {
                transform: rotate(36deg);
            }
            20% {
                transform: rotate(72deg);
            }
            30% {
                transform: rotate(108deg);
            }
            40% {
                transform: rotate(144deg);
            }
            50% {
                transform: rotate(180deg);
            }
            60% {
                transform: rotate(216deg);
            }
            70% {
                transform: rotate(252deg);
            }
            80% {
                transform: rotate(288deg);
            }
            90% {
                transform: rotate(324deg);
            }
            100% {
                transform: rotate(360deg);
            }
        }
    </style>
</html>

春联效果

春节快要到了,所以春联也整起来吧,使用了变换中的旋转,还有变化中心位置的修改,效果图如下:

源代码:

html 复制代码
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <div class="wrap">
            <div class="card">
                <div class="text">春</div>
            </div>
            <div class="two">
                <div class="text">到</div>
            </div>
            <div class="three">
                <div class="text">万</div>
            </div>
            <div class="for">
                <div class="text">家</div>
            </div>
        </div>
        <style>
            * {
                padding: 0;
                margin: 0;
                box-sizing: border-box;
            }

            html,
            body {
                width: 100%;
                height: 100%;
                background-color: skyblue;
            }

            .wrap {
                width: 100px;
                /* margin-top: 200px; */
                margin: 100px auto;
            }

            .card {
                width: 100px;
                height: 100px;
                background-color: red;
                transform: rotate(45deg);
                transform-origin: left top;
                animation: shark 3s infinite ease-in-out -6s;
            }

            .two {
                width: 100px;
                height: 100px;
                margin-top: 45px;
                background-color: red;
                transform: rotate(45deg);
                transform-origin: left top;
                animation: shark 2s infinite ease-in-out -5s;
            }

            .three {
                width: 100px;
                height: 100px;
                margin-top: 45px;
                background-color: red;
                transform: rotate(45deg);
                transform-origin: left top;
                animation: shark 3s infinite ease-in-out -4s;
            }

            .for {
                width: 100px;
                height: 100px;
                margin-top: 45px;
                background-color: red;
                transform: rotate(45deg);
                transform-origin: left top;
                animation: shark 2s infinite ease-in-out -3s;
            }

            .text {
                font-size: 50px;
                color: white;
                transform: rotate(-45deg) translate(10px, 10px);
            }

            @keyframes shark {
                0% {
                    transform: rotate(30deg);
                }

                50% {
                    transform: rotate(60deg);
                }

                100% {
                    transform: rotate(30deg);
                }
            }
        </style>
    </body>
</html>
相关推荐
wgod4 分钟前
new AbortController()
前端
UXbot10 分钟前
UXbot 是什么?一句指令生成完整应用的 AI 工具
前端·ai·交互·个人开发·ai编程·原型模式·ux
棒棒的唐25 分钟前
WSL2用npm安装的openclaw,无法正常使用openclaw gateway start启动服务的问题
前端·npm·gateway
哔哩哔哩技术33 分钟前
使用Compose Navigation3进行屏幕适配
前端
咬人喵喵1 小时前
E2.COOL 平台深度解析:从特效分类到实战操作指南
前端·编辑器·svg
RisunJan2 小时前
Linux命令-named-checkzone
linux·前端
小陈工2 小时前
Python Web开发入门(十):数据库迁移与版本管理——让数据库变更可控可回滚
前端·数据库·人工智能·python·sql·云原生·架构
吹晚风吧3 小时前
解决vite打包,base配置前缀,nginx的dist包找不到资源
服务器·前端·nginx
weixin199701080163 小时前
《施耐德商品详情页前端性能优化实战》
前端·性能优化
不想上班只想要钱3 小时前
模板里 item.xxx 报错 ,报 item的类型为未知
前端·vue