效果预览

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

https://codepen.io/zhang-ou/pen/GdrrZq

可交互视频教程

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

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

https://scrimba.com/c/cWknNUR

源代码下载

请从 github 下载。

https://github.com/comehope/front-end-daily-challenges/tree/master/007-3d-text-marquee-effects

代码解读

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

<div class="box">
<div class="inner">
<span>Hello World</span>
</div>
<div class="inner">
<span>Hello World</span>
</div>
</div>

居中显示:

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%;
}

大功告成!

知识点

前端每日实战:7# 视频演示如何用纯 CSS 创作一个 3D 文字跑马灯特效的更多相关文章

  1. 如何用纯 CSS 创作一个 3D 文字跑马灯特效

    效果预览 在线演示 按下右侧的"点击预览"按钮在当前页面预览,点击链接全屏预览. https://codepen.io/zhang-ou/pen/GdrrZq 可交互视频教程 此视 ...

  2. 前端每日实战:23# 视频演示如何用纯 CSS 创作一个菜单反色填充特效

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览.https://codepen.io/comehope/pen/qYMoPo 可交互视频教程 此视频是 ...

  3. 前端每日实战:27# 视频演示如何用纯 CSS 创作一个精彩的彩虹 loading 特效

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/vjvoow 可交互视频教程 此视频 ...

  4. 前端每日实战:1# 视频演示如何用纯 CSS 创作一个按钮文字滑动特效

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/zhang-ou/pen/GdpPLE 可交互视频教程 此视频 ...

  5. 前端每日实战:10# 视频演示如何用纯 CSS 创作一个同心圆弧旋转 loader 特效

    效果预览 按下右侧的"点击预览"按钮在当前页面预览,点击链接全屏预览. https://codepen.io/zhang-ou/pen/OZmXQX 可交互视频教程 此视频是可以交 ...

  6. 前端每日实战:157# 视频演示如何用纯 CSS 创作一个棋盘错觉动画(实际上每一行都是平行的)

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/VEyoGj 可交互视频 此视频是可 ...

  7. 前端每日实战:158# 视频演示如何用纯 CSS 创作一个雨伞 toggle 控件

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/pxLbjv 可交互视频 此视频是可 ...

  8. 前端每日实战:122# 视频演示如何用纯 CSS 创作一个苹果系统的相册图标

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/zJKwbO 可交互视频 此视频是可 ...

  9. 前端每日实战:156# 视频演示如何用纯 CSS 创作一个飞机舷窗风格的 toggle 控件

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/jeaOrw 可交互视频 此视频是可 ...

随机推荐

  1. shiro PermissionUtil

    package org.linlinjava.litemall.admin.util; import org.apache.shiro.authz.annotation.RequiresPermiss ...

  2. 绿洲作业第一周 - Y3每日中文学习任务清单

    尽量每天完成一首古诗. 如果孩子另有学习安排,可在周日(2.16)23:59前,完成任务.有兴趣.学有余力的孩子可以自我拓展其中的“寒假读诗”.

  3. [LC] 105. Construct Binary Tree from Preorder and Inorder Traversal

    Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  4. 树形dp(最小支配集)

    http://poj.org/problem?id=3659 #include<iostream> #include<cstring> #include<algorith ...

  5. Sampling Error|Sampling mean|population mean

    7.1 Sampling Error; the Need for Sampling Distributions 样本均值的三种表达: Sampling distribution of the samp ...

  6. 图形学创世纪——写在SIGGRAPH 40年的边上

    40年的边上" title="图形学创世纪--写在SIGGRAPH 40年的边上"> 前言: SIGGRAPH是由ACM SIGGRAPH(美国计算机协会计算机图形 ...

  7. Office 365 的安装方法

    一.在线安装 进入网址 https://www.office.com/ 使用office账号登陆 1.点击右上角安装office应用,选择第二项 其他安装选项 2.选择安装语言 点击高级,选择安装版本 ...

  8. delicate|definite|density|deny doing|draw up |draw on|no equal for|establish|equipped|

    ADJ-GRADED 技巧性很强的;注重细节的A delicate task, movement, action, or product needs or shows great skill and ...

  9. php--小数点问题

    1.用round去小数点后两位时,有时候会出现很长的小数解决方法 sprintf("%.2f",round($total_fee,2)); 使用sprintf再截取一遍.出现变态小 ...

  10. 关于angular跳转路由之后不能自动回到顶部的解决方法

    Question: angular2 scroll top on router change 当我们在第一个路由滑动到底部当我们点击导航跳转到另一个路由时页面没有回到顶部而是保持上一个路由的滚动位置, ...