如何在https://dekks.app上重新创建文本动画

发布于 2025-01-26 12:40:03 字数 2873 浏览 3 评论 0原文

我试图实现的内容

我只是尝试使用CSS实施此功能,但是我已经能够实现并不完全相同。我将包括我目前拥有的gif,但我无法公开它。但是,如果有什么在这里是指我使用的方法的codepen链接,我的编辑是我的编辑包括下面(无关紧要的内容,“填充文本”用作真实文本的占位符)。如果有人能帮助我,我会很高兴。 (请注意,我在大多数样式中都使用tailwind,而我仅在动画方面使用自定义CSS)。

html:

<div className="loading">
    <div style={{ "--i": "1" }}>
        <span className="text-blue-400 text-40 font-bold">
           Filler Text
        </span>
    </div>
    <div style={{ "--i": "3" }}>
        <span className="text-blue-400 text-40 font-bold">
            Filler Text
        </span>
    </div>
    <div style={{ "--i": "5" }}>
        <span className="text-blue-400 text-40 font-bold">
            Filler Text
        </span>
    </div>
    <div style={{ "--i": "7" }}>
        <span className="text-blue-400 text-40 font-bold">
            Filler Text
        </span>
    </div>
</div>

CSS:

.loading {
    position: relative;
    width: 50%;
    height: 120.48px;
    margin: 40px auto;
    transform-style: preserve-3d;
}
.loading:before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    /* box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.3); */
}

.loading div {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 12px;
    display: inline-block;
    background: transparent;
    transform-style: preserve-3d;
    perspective: 1000px;
    transform-origin: 100% 400%;
    overflow: hidden;
    animation: animate 4s linear infinite;
    animation-delay: calc(0.5s * var(--i));
    margin-left: 20px;
}
@keyframes animate {
    0% {
        transform: perspective(500px) translate3d(0, 0, 0);
        opacity: 0.5;
        box-shadow: 5px 5px 15px rgba(0, 0, 0, 0);
    }
    25% {
        transform: perspective(500px) translate3d(-10px, -20px, 20px);
        opacity: 1;
        box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.2);
    }
    35%,
    100% {
        transform: perspective(500px) translate3d(-10px, -20px, -150px);
        opacity: 0;
    }
}
.loading div span {
    position: absolute;
    top: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    /**background: url("/src/components/assets/images/blue-text-gradient.png");
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center;**/
}

参考实时网站以进行检查以下是链接: dekks
另外,请随时纠正我,因为这是我第一次在这里问一个问题。

What I am trying to implement

I have tried implementing this with just CSS but what I have been able to achieve is not quite the same. I would include a gif of what I have currently but I'm not able to make it public. But if anything here is the codepen link to the approach I utilized and my edit of the code is included below (irrelevant things commented out and "filler text" is used as a placeholder for real text7). I'd be glad if anyone can help me. (To be noted that I'm using Tailwind for most of the styling and I'm only using custom CSS for the animation aspect).

HTML:

<div className="loading">
    <div style={{ "--i": "1" }}>
        <span className="text-blue-400 text-40 font-bold">
           Filler Text
        </span>
    </div>
    <div style={{ "--i": "3" }}>
        <span className="text-blue-400 text-40 font-bold">
            Filler Text
        </span>
    </div>
    <div style={{ "--i": "5" }}>
        <span className="text-blue-400 text-40 font-bold">
            Filler Text
        </span>
    </div>
    <div style={{ "--i": "7" }}>
        <span className="text-blue-400 text-40 font-bold">
            Filler Text
        </span>
    </div>
</div>

CSS:

.loading {
    position: relative;
    width: 50%;
    height: 120.48px;
    margin: 40px auto;
    transform-style: preserve-3d;
}
.loading:before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    /* box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.3); */
}

.loading div {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 12px;
    display: inline-block;
    background: transparent;
    transform-style: preserve-3d;
    perspective: 1000px;
    transform-origin: 100% 400%;
    overflow: hidden;
    animation: animate 4s linear infinite;
    animation-delay: calc(0.5s * var(--i));
    margin-left: 20px;
}
@keyframes animate {
    0% {
        transform: perspective(500px) translate3d(0, 0, 0);
        opacity: 0.5;
        box-shadow: 5px 5px 15px rgba(0, 0, 0, 0);
    }
    25% {
        transform: perspective(500px) translate3d(-10px, -20px, 20px);
        opacity: 1;
        box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.2);
    }
    35%,
    100% {
        transform: perspective(500px) translate3d(-10px, -20px, -150px);
        opacity: 0;
    }
}
.loading div span {
    position: absolute;
    top: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    /**background: url("/src/components/assets/images/blue-text-gradient.png");
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center;**/
}

For reference to the live site for inspection here is the link: dekks.
Also, feel free to correct me as this is my first time asking a question here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无畏 2025-02-02 12:40:03

您应该查看此示例并相应地修改代码。



<h1>
  <span>always be</span>
  <div class="message">
    <div class="word1">close</div>
    <div class="word2">code</div>
    <div class="word3">creating</div>
  </div>
</h1>

CSS



* {
  box-sizing: border-box;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  width: 100vw;
}
h1 {
  color: #333;
  font-family: tahoma;
  font-size: 3rem;
  font-weight: 100;
  line-height: 1.5;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  position: relative;
  width: 550px;
}

h1 span {
  font-size: 40px;
  margin-left: 40px;
}

.message {
  background-color: yellow;
  color: #333;
  display: block;
  font-weight: 900;
  overflow: hidden;
  position: absolute;
  padding-left: 0.5rem;
  top: 0.2rem;
  left: 270px;
  animation: openclose 5s ease-in-out infinite;
}

.word1, .word2, .word3 {
  font-family: tahoma;
}

@keyframes openclose {
  0% {
    top: 0.2rem;
    width: 0;
  }
  5% {
    width: 0;
  }
  15% {
    width: 230px;
  }
  30% {
    top: 0.2rem;
    width: 230px;
  }
  33% {
    top: 0.2rem;
    width: 0;
  }
  35% {
    top: 0.2rem;
    width: 0;
  }
  38% {
    top: -4.5rem;
    
  }
  48% {
    top: -4.5rem;
    width: 190px;
  }
  62% {
    top: -4.5rem;
    width: 190px;
  }
  66% {
    top: -4.5rem;
    width: 0;
    text-indent: 0;
  }
  71% {
    top: -9rem;
    width: 0;
    text-indent: 5px;
  }
  86% {
    top: -9rem;
    width: 285px;
  }
  95% {
    top: -9rem;
    width: 285px;
  }
  98% {
    top: -9rem;
    width: 0;
    text-indent: 5px;
  }
  100% {
    top: 0;
    width: 0;
    text-indent: 0;
  }
}

You should look at this example and modify you code accordingly.



<h1>
  <span>always be</span>
  <div class="message">
    <div class="word1">close</div>
    <div class="word2">code</div>
    <div class="word3">creating</div>
  </div>
</h1>

CSS



* {
  box-sizing: border-box;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  width: 100vw;
}
h1 {
  color: #333;
  font-family: tahoma;
  font-size: 3rem;
  font-weight: 100;
  line-height: 1.5;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  position: relative;
  width: 550px;
}

h1 span {
  font-size: 40px;
  margin-left: 40px;
}

.message {
  background-color: yellow;
  color: #333;
  display: block;
  font-weight: 900;
  overflow: hidden;
  position: absolute;
  padding-left: 0.5rem;
  top: 0.2rem;
  left: 270px;
  animation: openclose 5s ease-in-out infinite;
}

.word1, .word2, .word3 {
  font-family: tahoma;
}

@keyframes openclose {
  0% {
    top: 0.2rem;
    width: 0;
  }
  5% {
    width: 0;
  }
  15% {
    width: 230px;
  }
  30% {
    top: 0.2rem;
    width: 230px;
  }
  33% {
    top: 0.2rem;
    width: 0;
  }
  35% {
    top: 0.2rem;
    width: 0;
  }
  38% {
    top: -4.5rem;
    
  }
  48% {
    top: -4.5rem;
    width: 190px;
  }
  62% {
    top: -4.5rem;
    width: 190px;
  }
  66% {
    top: -4.5rem;
    width: 0;
    text-indent: 0;
  }
  71% {
    top: -9rem;
    width: 0;
    text-indent: 5px;
  }
  86% {
    top: -9rem;
    width: 285px;
  }
  95% {
    top: -9rem;
    width: 285px;
  }
  98% {
    top: -9rem;
    width: 0;
    text-indent: 5px;
  }
  100% {
    top: 0;
    width: 0;
    text-indent: 0;
  }
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文