当前位置:网站首页>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.
边栏推荐
猜你喜欢

"Real" emotions dictionary based on the text sentiment analysis and LDA theme analysis

C language _ structure pointer array function voting system

Sping.事务的传播特性

MySQL的存储过程

【genius_platform软件平台开发】第七十四讲:window环境下的静态库和动态库的一些使用方法(VC环境)

leetcode-952:按公因数计算最大组件大小

Fiddler抓包模拟弱网络环境测试

射频器件的基本参数1

uniapp使用第三方字体

内网渗透——提权
随机推荐
倍增、DFS序
简易表白小页面
PDF split/merge
Interprocess communication study notes
87. 把字符串转换成整数
1782. 统计点对的数目 双指针
TiDB 操作实践 -- 备份与恢复
ROS Action通信
想要写出好的测试用例,先要学会测试设计
coldfusion8后台计划任务拿shell
16、注册中心-consul
Word/Excel 固定表格大小,填写内容时,表格不随单元格内容变化
ShardingSphere's vertical sub-database sub-table actual combat (5)
《MySQL数据库进阶实战》读后感(SQL 小虚竹)
【952. Calculate the maximum component size according to the common factor】
Chi-square distribution of digital image steganography
Xiaohei's leetcode journey: 117. Fill the next right node pointer of each node II
数字图像隐写术之JPEG 隐写分析
Teach you how to configure Jenkins automated email notifications
1.非类型模板参数 2.模板的特化 3.继承讲解