博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何用纯 CSS 创作一个 3D 文字跑马灯特效
阅读量:4328 次
发布时间:2019-06-06

本文共 1339 字,大约阅读时间需要 4 分钟。

1504257-20181119230449400-1147737281.gif

效果预览

按下右侧的“点击预览”按钮在当前页面预览,点击链接全屏预览。

可交互视频教程

此视频是可以交互的,你可以随时暂停视频,编辑视频中的代码。

请用 chrome, safari, edge 打开观看。

源代码下载

请从 github 下载。

代码解读

定义 dom,包含2组重复的文字:

Hello World
Hello World

居中显示:

html,

body {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}

设置容器的尺寸和文字样式:

.box {

display: flex;
}

.box .inner {

width: 200px;
height: 100px;
line-height: 100px;
font-size: 32px;
font-family: sans-serif;
font-weight: bold;
white-space: nowrap;
}

配色:

.box .inner:first-child {

background-color: indianred;
color: darkred;
}

.box .inner:last-child {

background-color: lightcoral;
color: antiquewhite;
}

设置 3d 效果:

.box .inner:first-child {

transform-origin: left;
transform: perspective(300px) rotateY(-67.3deg);
}

.box .inner:last-child {

transform-origin: right;
transform: perspective(300px) rotateY(67.3deg);
}

定义动画效果:

@keyframes marquee {

from {
left: 100%;
}

to {    left: -100%;}

}

把动画效果应用到文字上,并隐藏容器外的内容:

.box .inner span {

position: absolute;
animation: marquee 5s linear infinite;
}

.box .inner {

overflow: hidden;
}

让左侧的文字延迟运动,模拟出2组文字连贯运动的效果:

.box .inner:first-child span {

animation-delay: 2.5s;
left: -100%;
}
```

大功告成!

知识点

  • transform-origin
  • perspective
  • rotateY()
  • animation-delay

原文地址:https://segmentfault.com/a/1190000014663038

转载于:https://www.cnblogs.com/lalalagq/p/9986420.html

你可能感兴趣的文章
python的字符串内建函数
查看>>
Spring - DI
查看>>
微软自己的官网介绍 SSL 参数相关
查看>>
Composite UI Application Block (CAB) 概念和术语
查看>>
ajax跨域,携带cookie
查看>>
阶段3 2.Spring_01.Spring框架简介_03.spring概述
查看>>
阶段3 2.Spring_02.程序间耦合_1 编写jdbc的工程代码用于分析程序的耦合
查看>>
阶段3 2.Spring_01.Spring框架简介_04.spring发展历程
查看>>
阶段3 2.Spring_02.程序间耦合_3 程序的耦合和解耦的思路分析1
查看>>
阶段3 2.Spring_02.程序间耦合_5 编写工厂类和配置文件
查看>>
阶段3 2.Spring_01.Spring框架简介_05.spring的优势
查看>>
阶段3 2.Spring_02.程序间耦合_7 分析工厂模式中的问题并改造
查看>>
阶段3 2.Spring_02.程序间耦合_4 曾经代码中的问题分析
查看>>
阶段3 2.Spring_03.Spring的 IOC 和 DI_2 spring中的Ioc前期准备
查看>>
阶段3 2.Spring_03.Spring的 IOC 和 DI_4 ApplicationContext的三个实现类
查看>>
阶段3 2.Spring_02.程序间耦合_8 工厂模式解耦的升级版
查看>>
阶段3 2.Spring_03.Spring的 IOC 和 DI_6 spring中bean的细节之三种创建Bean对象的方式
查看>>
阶段3 2.Spring_04.Spring的常用注解_3 用于创建的Component注解
查看>>
阶段3 2.Spring_04.Spring的常用注解_2 常用IOC注解按照作用分类
查看>>
阶段3 2.Spring_09.JdbcTemplate的基本使用_5 JdbcTemplate在spring的ioc中使用
查看>>