当前位置:网站首页>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.
边栏推荐
- pycharm重命名后无法运行(报错: can‘t open file......No such file or directory)
- Know what DTU is 4GDTU equipment
- rpm install postgresql12
- 打印任务排序 js od华为
- JPEG Steganalysis of Digital Image Steganography
- 16、注册中心-consul
- 【Map与Set】之LeetCode&牛客练习
- Distributed. Distributed lock
- Gateway路由的配置方式
- Kyushu cloud as cloud computing standardization excellent member unit
猜你喜欢
调度中心xxl-Job
Analyze the capabilities and scenarios of the cloud native message flow system Apache Pulsar
MySql installation and configuration super detailed tutorial and simple method of building database and table
tensorflow与GPU版本对应安装问题
Word/Excel 固定表格大小,填写内容时,表格不随单元格内容变化
Distributed. Idempotency
leetcode-399:除法求值
蓝牙mesh系统开发二 mesh节点开发
设置浏览器滚动条样式
Mysql: Invalid default value for TIMESTAMP
随机推荐
What is the ideal college life?
MySql的初识感悟,以及sql语句中的DDL和DML和DQL的基本语法
TiDB之rawkv升级之路v5.0.4--&gt;v6.1.0
PDF 拆分/合并
Know what DTU is 4GDTU equipment
The difference between 4G communication module CAT1 and CAT4
类似 MS Project 的项目管理工具有哪些
最高月薪20K?平均薪资近万...在华为子公司工作是什么体验?
What have I experienced when I won the offer of BAT and TMD technical experts?
Jiuzhou Cloud was selected into the "Trusted Cloud's Latest Evaluation System and the List of Enterprises Passing the Evaluation in 2022"
倍增、DFS序
24. Please talk about the advantages and disadvantages of the singleton pattern, precautions, usage scenarios
TiKV主要内存结构和OOM排查总结
Shell 脚本循环遍历日志文件中的值进行求和并计算平均值,最大值和最小值
MySQL的存储过程
九州云获评云计算标准化优秀成员单位
【Map与Set】之LeetCode&牛客练习
VS warning LNK4099:未找到 PDB 的解决方案
MySQL的安装教程(嗷嗷详细,包教包会~)
简易表白小页面