CSS前端学习(online tuorials)旋转动画

index.html

<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]>      <html class="no-js"> <!--<![endif]-->
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>course2</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="自己定义的CSS.css">
    </head>
    <body>
   
        <div class = 'loader'>
            <div></div>
            <div></div>
            <div></div>
            <div></div>

        </div>
        

    </body>
</html>

style.css

*
{
   margin: 0;
   padding: 0;
   box-sizing: border-box; 
}

body
{
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: #0e2223;


}

.loader
{
    position: relative;
    width: 150px;
    height: 150px;
    background: #03e9f4;
    transition: 0.5s;

}

.loader div
{
    position: absolute;
    top: -100%;
    left: 0;
    width: 100%;
    height: 100%;
    border: 4px solid #03e9f4;
    transition: 0.5s;
    transform-origin: bottom right;
    animation: animateBox 2s ease-in infinite;
}

.loader div:nth-child(2)
{
    transform-origin: top left;
    top: 100%;
    left: 0;

}

.loader div:nth-child(3)
{
    transform-origin: bottom left;
    top: 0;
    left: 100%;

}

.loader div:nth-child(4)
{
    transform-origin: top right;
    top: 0;
    left: -100%;

}

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

    50%,100%
    {
        transform: rotate(180deg);
    }

}

.loader :hover,
.loader:hover div
{
    background: #03e9f4;
    box-shadow: 0 0 5px #03e9f4,
    0 0 25px #03e9f4,
    0 0 50px #03e9f4,
    0 0 200px #03e9f4;
}

transition: 0.5s; 为背景颜色变化和其他属性变化添加一个0.5秒的过渡效果。

transform-origin: bottom right; 设置旋转的基点为子元素的右下角。

animation: animateBox 2s ease-in infinite; 应用 animateBox (keyframes ,这个动画定义了从 0deg 旋转到 180deg 的过程。子元素在前50%的时间里会旋转180度,并在接下来的50%时间里保持这个角度(因为 50% 和 100% 的状态是相同的)),持续2秒,使用 ease-in 函数进行无限循环。

:hover 伪类用于当鼠标悬停在 .loader 上时,改变 .loader 和其子元素的样式。

可以选择图片的形式做效果。
.loader {
position: relative;
width: 150px;
height: 150px;
background: url(‘替换图片.jpg’) no-repeat center/cover;
transition: 0.5s;
}

或者
border-radius: 50%;添加属性变成圆形。

修改animateBox,利用rotate3d可以做3D翻转。
@keyframes animateBox
{
0% {
transform: rotate3d(1, 1, 0, 0deg);
}
50% {
transform: rotate3d(1, 1, 0, 180deg);
}
100% {
transform: rotate3d(1, 1, 0, 360deg);
}

}

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值