仿写css小项目(超简单)——加载动画

从B站上看到的小项目,炫酷又简单。

HTML模块:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引用 -->
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <div class="loader">
        <span></span>
        <span></span>
        <span></span>
        <h2>Loading...</h2>
    </div>
</body>

</html>

 CSS模块:

* {
    /* 清除默认边距 */
    margin: 0;
    padding: 0;
    /* box-sizing: border-box;元素的总高度和宽度包含内边距和边框(padding 与 border) : */
    box-sizing: border-box;
}

body {
    /* display: flex; 弹性布局*/
    display: flex;
    /*justify-content: center;表示居中排列 */
    justify-content: center;
    /* 居中对齐弹性盒的各项 <div> 元素: */
    align-items: center;
    /* 设置背景颜色 */
    background-color: rgb(79, 80, 87);
    /* 设置段落的最小高度 */
    min-height: 100vh;
}

.loader {
    /* position的属性之一:relative(相对定位):生成相对定位的元素,通过top,bottom,left,right的设置相对于其正常(原先本身)位置进行定位。可通过z-index进行层次分级。   */
    position: relative;
    width: 200px;
    height: 200px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.loader span {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /*  */
    border: 2px solid skyblue;
    pointer-events: none;
    /* 语法:animation: name duration timing-function delay iteration-count direction fill-mode play-state; */
    animation: animate 5s linear infinite;
}


/* 这里的椭圆数值 用到的网址:https://mdbootstrap.com/docs/standard/tools/design/fancy-border-radius/*/

.loader span:nth-child(1) {
    border-radius: 44% 56% 58% 42% / 52% 49% 51% 48%;
}

.loader span:nth-child(2) {
    animation-direction: reverse;
    border-radius: 73% 27% 20% 80% / 40% 33% 67% 60%;
}

.loader span:nth-child(3) {
    animation-duration: 3s;
    border-radius: 42% 58% 64% 36% / 66% 33% 67% 34%;
}

@keyframes animate {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

.loader h2 {
    color: skyblue;
    font-family: consolas;
    font-weight: 500;
    box-shadow: 2px 0 0 #fff;
    /* 将超出的部分进行隐藏 */
    overflow: hidden;
    /* 语法:animation: name duration timing-function delay iteration-count direction fill-mode play-state; */
    animation: textTyping 3s linear infinite;
}


/*定义动画,keyframe是关键帧,里面的百分比要是整数  */

@keyframes textTyping {
    0% {
        width: 0px;
    }
    20% {
        width: 131.96px;
    }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,你需要在你的电脑上安装 Visual Studio Code (VS Code)。 然后,按照以下步骤创建一个仿写小米官网的项目: 1. 打开 VS Code 并创建一个新的文件夹,命名为 "xiaomi-clone"(或者你喜欢的其他名字)。 2. 在 VS Code 中打开终端(Terminal)。在菜单栏中选择 "View" -> "Terminal",或使用快捷键 Ctrl + `。 3. 在终端中输入以下命令,创建一个新的 HTML 文件并进入文件夹: ``` mkdir xiaomi-clone cd xiaomi-clone touch index.html ``` 4. 在 VS Code 中打开 "index.html" 文件,并输入以下基本的 HTML 结构: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Xiaomi Clone</title> </head> <body> <!-- 这里放置页面内容 --> </body> </html> ``` 5. 在 `<body>` 标签内添加页面内容。你可以通过查看小米官网来获取页面布局和内容的灵感。使用 HTMLCSS 创建仿写页面结构和样式。 6. 在终端中输入以下命令,创建一个新的 CSS 文件并进入文件夹: ``` touch style.css ``` 7. 在 VS Code 中打开 "style.css" 文件,并添加你的样式代码。你可以使用 CSS 来设置页面的布局、字体、颜色等。 8. 在 "index.html" 文件的 `<head>` 标签中添加链接到 "style.css" 文件的代码: ```html <link rel="stylesheet" href="style.css"> ``` 9. 继续完善页面内容和样式,根据需要添加 JavaScript 代码来实现交互功能。 10. 最后,通过在浏览器中打开 "index.html" 文件来预览你的仿写小米官网项目。 这只是一个简单的指南,帮助你开始创建仿写小米官网的项目。你可以根据需要添加更多的页面和功能。祝你好运!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值