RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 808075
Accepted
Arthur
Arthur
Asked:2020-04-02 02:52:11 +0000 UTC2020-04-02 02:52:11 +0000 UTC 2020-04-02 02:52:11 +0000 UTC

如何制作文字破解效果

  • 772

此 QA 是过去的延续(文本样式SVG)。

在这个 QA (Question-Answer) 中,我们将看到Crack effect,下面将给出这种效果的示例,总共有 3 个。

第一个例子(沿着文本出现裂缝并进一步转换):

在此处输入图像描述

第二个例子(文字的上半部分在挥剑后折断并平滑滑出,尽管文字本身的角度应该在 10 左右1-2deg):

在此处输入图像描述

第三个例子(与第二个类似,但有区别,有两个笔划沿和横跨文本):

在此处输入图像描述

文本将在 上实现SVG,放置通过clipPath,动画通过@keyframes。

PS点击后所有示例都可以使用。

html
  • 3 3 个回答
  • 10 Views

3 个回答

  • Voted
  1. Arthur
    2020-04-02T02:52:28Z2020-04-02T02:52:28Z

    第二个例子:

    • 在这个例子中,使用了相同的定位,除了你需要rect在1deg点击添加之后 旋转transform: translateX(N):

    * {
      margin: 0;
      padding: 0;
    }
    
    body {
      background-color: #000000;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
    }
    
    svg text {
      font-family: 'Russo One', sans-serif;
      text-transform: uppercase;
      font-size: 4em;
      pointer-events: none;
    }
    
    svg rect {
      transform: rotate(-1deg);
      transition: cubic-bezier(1, 0.3, 0.6, 1) 3.5s;
    }
    
    #top { 
      animation: offsetXF 1s infinite;
    }
    
    #bottom { 
      animation: offsetXT 1s infinite;
    }
    
    @keyframes offsetXF {
      50% {
        transform: translateX(-30px) rotate(-1deg);
        opacity: 0;
      }
    }
    
    @keyframes offsetXT {
      50% {
        transform: translateX(30px) rotate(-1deg);
        opacity: 0;
      }
    }
    <link href="https://fonts.googleapis.com/css?family=Russo+One" rel="stylesheet">
    <svg viewBox="0 0 710 200" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
      <defs>
        <clipPath id="clip">
          <text text-anchor="middle" x="50%" y="49%">Breaking text</text>
        </clipPath>
      </defs>
      <g>
      <!--Смещение по оси X-->
        <rect id="top" clip-path="url(#clip)" width="710" height="50" y="26" fill="white"/>
        <rect id="bottom" clip-path="url(#clip)" width="710" height="50" y="75" fill="white"/>
      </g>
    </svg>

    • 仍有待完成polygon,这将模拟用剑(或武士刀:D)挥动,在本示例的最终版本中,我们还将沿轴移动它X,大约移动700-800px:

    <svg viewBox="0 0 710 200" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
      <polygon id="sword" points="0,75 55,67 70,75 56,80" fill="silver" transform="scale(2)"/>
    </svg>

    • 最终版本。点击之后,我们改变了 的位置polygon,同时为 增加了一个类#top,这就是为什么文本的顶部发生了移位,并且滑动后也有延迟,因为rect添加了 y transition-delay:

    function crack() {
      var rect = document.getElementById("top");
      var polygon = document.getElementById("sword");
      rect.classList.add("active");
      polygon.classList.add("_activate");
    }
    * {
      margin: 0;
      padding: 0;
    }
    
    body {
      background-color: #000000;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
    }
    
    svg text {
      font-family: 'Russo One', sans-serif;
      text-transform: uppercase;
      font-size: 4em;
      pointer-events: none;
    }
    
    svg rect {
      transform: rotate(-1deg);
      transition: cubic-bezier(1, 0.3, 0.6, 1) 3.5s;
      transition-delay: 1s;
    }
    
    #top.active {
      transform: translateX(-30px) rotate(-1deg);
      opacity: 0;
    }
    
    #sword {
      transform: rotate(-1deg) translateX(-100px);
    }
    
    #sword._activate {
      animation: attack 0.4s 1;
    }
    
    @keyframes attack {
      to {
        transform: rotate(-1deg) translateX(750px);
      }
    }
    <link href="https://fonts.googleapis.com/css?family=Russo+One" rel="stylesheet">
    <svg viewBox="0 0 710 200" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
      <defs>
        <clipPath id="clip">
          <text text-anchor="middle" x="50%" y="49%">Breaking text</text>
        </clipPath>
      </defs>
      <g onclick="crack()">
        <rect id="top" clip-path="url(#clip)" width="710" height="50" y="26" fill="white"/>
        <rect clip-path="url(#clip)" width="710" height="50" y="75" fill="white"/>
        <polygon id="sword" points="0,75 55,67 70,75 56,80" fill="silver"/>
      </g>
    </svg>

    • 14
  2. Best Answer
    Arthur
    2020-04-02T02:52:42Z2020-04-02T02:52:42Z

    第一个例子:

    • 文本的两个部分都在 中rect,我们用 将文本本身插入其中clipPath,然后将它们沿轴定位Y,这里是定位文本前半部分和后半部分的示例:

    * {
      margin: 0;
      padding: 0;
    }
    
    body {
      background-color: #000000;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    
    svg text {
      font-family: 'Russo One', sans-serif;
      text-transform: uppercase;
      font-size: 5em;
      pointer-events: none;
      user-select: none;
    }
    <link href="https://fonts.googleapis.com/css?family=Russo+One" rel="stylesheet">
    <svg width="710" height="200" viewBox="0 0 710 200" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
      <defs>
        <clipPath id="clip">
          <text text-anchor="middle" x="50%" y="50%">Breaking text</text>
        </clipPath>
      </defs>
      <rect id="top" class="rectangle" clip-path="url(#clip)" width="710" height="50" fill="white">
      <!--Смещение по оси Y-->
      <animate attributeName="y" values="-10;26;-10" dur="3s" repeatCount="indefinite"/>
      </rect>
      <rect id="bottom" class="rectangle" clip-path="url(#clip)" width="710" height="50" fill="white">
      <!--Смещение по оси Y-->
      <animate attributeName="y" values="103;75;103" dur="3s" repeatCount="indefinite"/>
      </rect>
    </svg>

    • 定位文本后,让我们使用 CSS 属性制作一个简单的动画 -transform并添加transition,即 cubic-bezier. 但首先,我们将遍历每个rect'y 并给他们一个类active:

    function crack() {
      var rect = document.getElementsByTagName("rect");
      Array.from(rect).forEach(x => x.classList.toggle("active"));
    }
    * {
      margin: 0;
      padding: 0;
    }
    
    body {
      background-color: #000000;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    
    svg text {
      font-family: 'Russo One', sans-serif;
      text-transform: uppercase;
      font-size: 5em;
      pointer-events: none;
      user-select: none;
    }
    
    svg rect {
      transition: cubic-bezier(0.1, 0.3, 0.5, 1) .1s;
    }
    
    rect.active {
      transform: translateX(-3px) rotate(-0.15deg);
    }
    
    rect.active:last-child {
      transform: translateX(3px) rotate(0.15deg);
    }
    <link href="https://fonts.googleapis.com/css?family=Russo+One" rel="stylesheet">
    <svg width="710" height="200" viewBox="0 0 710 200" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
      <defs>
        <clipPath id="clip">
          <text text-anchor="middle" x="50%" y="50%">Breaking text</text>
        </clipPath>
      </defs>
      <g onclick="crack()">
        <rect id="top" class="rectangle" clip-path="url(#clip)" width="710" height="50" y="26" fill="white"/>
        <rect id="bottom" class="rectangle" clip-path="url(#clip)" width="710" height="50" y="75" fill="white"/>
      </g>
    </svg>

    • 14
  3. Arthur
    2020-04-02T02:52:11Z2020-04-02T02:52:11Z

    第三个例子:

    • 而不是两个rect,我们将使用四个,对于我制作的每两个部分clipPath(我没有找到更好的方法,我会很高兴关于如何使其“更清洁”:) 的建议:
      PS大约是我们应该得到的。

    * {
      margin: 0;
      padding: 0;
    }
    
    body {
      background-color: #000000;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
    }
    
    svg rect {
      fill: white;
    }
    <svg viewBox="-30 0 740 200" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
      <!-- FOUR RECTS -->
      <g>
        <rect clip-path="url(#clip)" width="336" height="50" y="26">
          <animateTransform attributeName="transform" type="translate" values="0 0; -20 -20; 0 0" dur="3s" repeatCount="indefinite"/>
        </rect>
        <rect clip-path="url(#clip)" width="336" height="50" y="75">
          <animateTransform attributeName="transform" type="translate" values="0 0; -20 20; 0 0" dur="3s" repeatCount="indefinite"/>
        </rect>
        <rect clip-path="url(#clip)" width="336" height="50" x="336" y="26">
          <animateTransform attributeName="transform" type="translate" values="0 0; 20 -20; 0 0" dur="3s" repeatCount="indefinite"/> 
        </rect>
        <rect clip-path="url(#clip)" width="336" x="336" height="50" y="75">
          <animateTransform attributeName="transform" type="translate" values="0 0; 20 20; 0 0" dur="3s" repeatCount="indefinite"/> 
        </rect>
      </g>
    </svg>

    • 这三个例子都是相似的,所以没有必要重复rect添加类来模仿波浪和其余部分(不要认为它是懒惰:)))),其实看看:

    function doubleCrack() {
      var rect = document.getElementsByTagName("rect");
      var polygon = document.getElementById("horizontal");
      var polygonTwo = document.getElementById("vertical");
    
      polygon.classList.add("_activate");
      polygonTwo.classList.add("_activate");
    
      Array.from(rect).forEach(x => x.classList.add("_activate-rect"));
    }
    * {
      margin: 0;
      padding: 0;
    }
    
    body {
      background-color: #000000;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
    }
    
    svg text {
      font-family: "Russo One", sans-serif;
      text-transform: uppercase;
      font-size: 5em;
      pointer-events: none;
    }
    
    svg rect {
      transition: 2s;
      transition-delay: 1s;
      fill: white;
    }
    
    #horizontal {
      transform: translateX(-100px);
    }
    
    #vertical {
      transform: translate(335px, 150px);
    }
    
    #horizontal._activate {
      animation: attack 0.4s 1;
    }
    
    #vertical._activate {
      animation: attack-2 0.4s 1;
      animation-delay: 0.4s;
    }
    
    #top._activate-rect {
    	transform: translate(-20px, -20px);
    	opacity: 0;
    }
    
    #bottom._activate-rect {
    	transform: translate(-20px, 20px);
    	opacity: 0;
    }
    
    #topN._activate-rect {
    	transform: translate(20px, -20px);
    	opacity: 0;
    }
    
    #bottomN._activate-rect {
    	transform: translate(20px, 20px);
    	opacity: 0;
    }
    
    @keyframes attack {
      to {
        transform: translateX(750px);
      }
    }
    
    @keyframes attack-2 {
      to {
        transform: translateX(335px) translateY(-150px);
      }
    }
    
    @keyframes break {
      to {
        transform: translateX(320px);
      }
    }
    <link href="https://fonts.googleapis.com/css?family=Russo+One" rel="stylesheet">
    <svg viewBox="0 0 740 200" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
      <defs>
        <!-- FIRST SIDE -->
        <clipPath id="clip">
          <text text-anchor="middle" x="368" y="50%">Breaking text</text>
        </clipPath>
        <!-- SECOND SIDE -->
        <clipPath id="clipN">
          <text text-anchor="middle" x="370" y="50%">Breaking text</text>
        </clipPath>
      </defs>
      <!-- FOUR RECTS -->
      <g onclick="doubleCrack()">
        <rect id="top" clip-path="url(#clip)" width="336" height="50" y="26"/>
        <rect id="bottom" clip-path="url(#clip)" width="336" height="50" y="75"/>
        <rect id="topN" clip-path="url(#clipN)" width="380" height="50" x="335" y="26"/>
        <rect id="bottomN" clip-path="url(#clipN)" width="380" height="50" x="335" y="75"/>
      </g>
      <!-- SWORDS -->
      <g>		
        <polygon id="horizontal" points="0,75 55,67 70,75 56,80" fill="silver"/>
        <polygon id="vertical" points="0,60 5,68 0,100 -5,68" fill="silver"/>
      </g>
    </svg>

    • 12

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    是否可以在 C++ 中继承类 <---> 结构?

    • 2 个回答
  • Marko Smith

    这种神经网络架构适合文本分类吗?

    • 1 个回答
  • Marko Smith

    为什么分配的工作方式不同?

    • 3 个回答
  • Marko Smith

    控制台中的光标坐标

    • 1 个回答
  • Marko Smith

    如何在 C++ 中删除类的实例?

    • 4 个回答
  • Marko Smith

    点是否属于线段的问题

    • 2 个回答
  • Marko Smith

    json结构错误

    • 1 个回答
  • Marko Smith

    ServiceWorker 中的“获取”事件

    • 1 个回答
  • Marko Smith

    c ++控制台应用程序exe文件[重复]

    • 1 个回答
  • Marko Smith

    按多列从sql表中选择

    • 1 个回答
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Suvitruf - Andrei Apanasik 什么是空? 2020-08-21 01:48:09 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5