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

Set the browser scrollbar style

The sword refers to offer17---print the n digits from 1 to the largest

Google官方控件ShapeableImageView使用

关于Redis相关内容的基础学习

I have been working in software testing for 3 years, how did I go from just getting started to automated testing?

Word 表格跨页,仍然显示标题

分布式.幂等性

Centos 7.9 install PostgreSQL14.4 steps

MySQL的分页你还在使劲的limit?

GCC Rust获批将被纳入主线代码库,或将于GCC 13中与大家见面
随机推荐
倍增、DFS序
聚簇索引和非聚簇索引到底有什么区别
Xiaohei's leetcode journey: 104. The maximum depth of a binary tree
《MySQL数据库进阶实战》读后感(SQL 小虚竹)
Gateway路由的配置方式
孩子的编程启蒙好伙伴,自己动手打造小世界,长毛象教育AI百变编程积木套件上手
coldfusion8后台计划任务拿shell
进程间通信学习笔记
pc端判断当前使用浏览器类型
有没有可以做副业可以日入300元方法?
What have I experienced when I won the offer of BAT and TMD technical experts?
【flask入门系列】Flask-SQLAlchemy的使用
Fiddler抓包模拟弱网络环境测试
Parameter introduction and selection points of wireless module
《实战》基于电商领域的词性提取及其决策树模型建模
计算S=a+aa+…+aa…a
RTL8720DN开发笔记一 环境搭建与mqtt实例
JPEG Steganalysis of Digital Image Steganography
想要写出好的测试用例,先要学会测试设计
pycharm重命名后无法运行(报错: can‘t open file......No such file or directory)