当前位置:网站首页>Simple confession page
Simple confession page
2022-07-31 01:39:00 【盖玥希圈外男友(섭소우)】
目录
需求
Another afternoon without life......做个简单的cssAnimation play!
很简单,Put several lines of different text“我爱你”放在页面中,Just move chaotically.
思路和代码
对于结构,需要一个父元素container,Put a lot in ititem,这些itemIt's all kinds of text“我爱你”.给这些item加上动画,Randomly set different delay times and durations,This creates a cluttered effect.
过于简单,直接上代码:
html部分
<div class="container">
<div class="item">我爱你</div>
<div class="item">I Love You</div>
<div class="item">사랑해요</div>
<div class="item">愛する</div>
<div class="item">EU te amo</div>
<div class="item">Je t' aime</div>
<div class="item">Ich liebe dich</div>
</div>
css部分
.container {
width: 500px;
height: 700px;
margin: auto;
background-color: pink;
}
.item {
width: 300px;
height: 50px;
font-size: 30px;
font-family: 'Courier New', Courier, monospace;
color: white;
}
.item:nth-child(1) {
animation: move 10s 0.5s alternate-reverse linear infinite both;
}
.item:nth-child(2) {
animation: move 8s 1s alternate-reverse linear infinite both;
}
.item:nth-child(3) {
animation: move 7s 0.8s alternate-reverse linear infinite both;
}
.item:nth-child(4) {
animation: move 6s 0.7s alternate-reverse linear infinite both;
}
.item:nth-child(5) {
animation: move 10s 1.1s alternate-reverse linear infinite both;
}
.item:nth-child(6) {
animation: move 9s 1.3s alternate-reverse linear infinite both;
}
.item:nth-child(7) {
animation: move 5s 1s alternate-reverse linear infinite both;
}
@keyframes move {
from {
transform: translate(0);
}
10% {
transform: translate(300px, 40px);
}
20% {
transform: translate(0px, 80px);
}
30% {
transform: translate(300px, 120px);
}
40% {
transform: translate(0px, 160px);
}
50% {
transform: translate(300px, 200px);
}
60% {
transform: translate(0px, 240px);
}
70% {
transform: translate(300px, 280px);
}
80% {
transform: translate(0px, 320px);
}
90% {
transform: translate(300px, 360px);
}
100% {
transform: translate(0px, 400px);
}
}
This basically works out.看效果.
实现效果
效果还算可以,It's just for fun after all.
进一步
如果现在我要求,鼠标hover某个item的时候,it changes color,Also pause the animation,应该怎么办?
很简单,直接添加一个hover伪类即可.修改后的css:
.container {
width: 500px;
height: 700px;
margin: auto;
background-color: pink;
}
.item {
width: 300px;
height: 50px;
font-size: 30px;
font-family: 'Courier New', Courier, monospace;
color: white;
}
.item:hover {
color: antiquewhite;
cursor: pointer;
animation-play-state: paused;
}
.item:nth-child(1) {
animation: move 10s 0.5s alternate-reverse linear infinite both;
}
.item:nth-child(2) {
animation: move 8s 1s alternate-reverse linear infinite both;
}
.item:nth-child(3) {
animation: move 7s 0.8s alternate-reverse linear infinite both;
}
.item:nth-child(4) {
animation: move 6s 0.7s alternate-reverse linear infinite both;
}
.item:nth-child(5) {
animation: move 10s 1.1s alternate-reverse linear infinite both;
}
.item:nth-child(6) {
animation: move 9s 1.3s alternate-reverse linear infinite both;
}
.item:nth-child(7) {
animation: move 5s 1s alternate-reverse linear infinite both;
}
@keyframes move {
from {
transform: translate(0);
}
10% {
transform: translate(300px, 40px);
}
20% {
transform: translate(0px, 80px);
}
30% {
transform: translate(300px, 120px);
}
40% {
transform: translate(0px, 160px);
}
50% {
transform: translate(300px, 200px);
}
60% {
transform: translate(0px, 240px);
}
70% {
transform: translate(300px, 280px);
}
80% {
transform: translate(0px, 320px);
}
90% {
transform: translate(300px, 360px);
}
100% {
transform: translate(0px, 400px);
}
}
I was excited to try it,结果发现,hover的时候,The text color did change,But the animation doesn't pause.
这是为什么呢?I thought it was a typo in the code,But double check,并没有错误.
后来灵光一动,发现了问题.我把hover写在了item:nth-child的前面.在hoverThe state of the animation set in is paused,But the state set in this child element selector is running,Overrides the previous pause.因此,必须把hoverPlaced after the child element pseudo-class selector.
修改代码:
.container {
width: 500px;
height: 700px;
margin: auto;
background-color: pink;
}
.item {
width: 300px;
height: 50px;
font-size: 30px;
font-family: 'Courier New', Courier, monospace;
color: white;
}
.item:nth-child(1) {
animation: move 10s 0.5s alternate-reverse linear infinite both;
}
.item:nth-child(2) {
animation: move 8s 1s alternate-reverse linear infinite both;
}
.item:nth-child(3) {
animation: move 7s 0.8s alternate-reverse linear infinite both;
}
.item:nth-child(4) {
animation: move 6s 0.7s alternate-reverse linear infinite both;
}
.item:nth-child(5) {
animation: move 10s 1.1s alternate-reverse linear infinite both;
}
.item:nth-child(6) {
animation: move 9s 1.3s alternate-reverse linear infinite both;
}
.item:nth-child(7) {
animation: move 5s 1s alternate-reverse linear infinite both;
}
@keyframes move {
from {
transform: translate(0);
}
10% {
transform: translate(300px, 40px);
}
20% {
transform: translate(0px, 80px);
}
30% {
transform: translate(300px, 120px);
}
40% {
transform: translate(0px, 160px);
}
50% {
transform: translate(300px, 200px);
}
60% {
transform: translate(0px, 240px);
}
70% {
transform: translate(300px, 280px);
}
80% {
transform: translate(0px, 320px);
}
90% {
transform: translate(300px, 360px);
}
100% {
transform: translate(0px, 400px);
}
}
.item:hover {
color: antiquewhite;
cursor: pointer;
animation-play-state: paused;
}
最终效果
很好!
总结
A very, very simple little case.以后记住,在加hover的时候,Put it in the back as much as possible,in case it is overridden by other styles.
边栏推荐
- 小黑leetcode之旅:104. 二叉树的最大深度
- Likou Daily Question - Day 46 - 704. Binary Search
- 九州云获评云计算标准化优秀成员单位
- 《实战》基于电商领域的词性提取及其决策树模型建模
- "Actual Combat" based on part-of-speech extraction in the field of e-commerce and its decision tree model modeling
- 35. 反转链表
- MySQL的安装教程(嗷嗷详细,包教包会~)
- Meta元宇宙部门第二季度亏损28亿 仍要继续押注?元宇宙发展尚未看到出路
- GCC Rust获批将被纳入主线代码库,或将于GCC 13中与大家见面
- tensorflow与GPU版本对应安装问题
猜你喜欢
随机推荐
Multiplication, DFS order
1.非类型模板参数 2.模板的特化 3.继承讲解
关于Redis相关内容的基础学习
【微信小程序】一文带你了解数据绑定、事件绑定以及事件传参、数据同步
Know what DTU is 4GDTU equipment
调度中心xxl-Job
Basic Parameters of RF Devices 2
MySQL (6)
MySql的初识感悟,以及sql语句中的DDL和DML和DQL的基本语法
仿牛客网项目总结
勾股数元组 od js
Jetpack Compose学习(8)——State及remeber
TiKV主要内存结构和OOM排查总结
PDF 拆分/合并
蓝牙mesh系统开发二 mesh节点开发
Meta元宇宙部门第二季度亏损28亿 仍要继续押注?元宇宙发展尚未看到出路
android的webview缓存相关知识收集
What have I experienced when I won the offer of BAT and TMD technical experts?
C语言_结构体指针数组函数选票系统
GCC Rust is approved to be included in the mainline code base, or will meet you in GCC 13