Simple implementation of handheld barrage function + text shaking special effects code based on JS

Simple implementation of handheld barrage function + text shaking special effects code based on JS

There was a shaking barrage on TikTok a while ago that was quite popular, so I decided to imitate it. Without further ado, let’s take a look at the effect first…

Effect display

insert image description here

The GIF image looks a bit blurry, but the actual effect is still good.

At first glance, I don’t know what to do, so let’s break down the functions to be implemented first.

  1. Generate a full-screen black background, write text, and center the content
  2. Achieving seamless scrolling
  3. Realize text shaking effects
  4. Rotate 90 degrees (horizontal display by default)

The code is as follows

.html

 <div class="barrage-box">
  <div class="text">Shaking subtitles</div>
 </div>

.css

.barrage-box {
  width: 100vh;
  height: 100vw;
  transform-origin: 50vw 50vw;
  transform: rotate(90deg);
  white-space: nowrap;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #000;
  overflow: hidden;
  animation: aniShake 0.5s linear infinite;
 }

 .text {
  width: 100%;
  font-size: 50px;
  color: #FFF;
  animation: aniMove 5s linear infinite;
  animation-fill-mode: forwards;
 }

 /* Text scrolling */
 @keyframes aniMove {
  0% { transform: translateX(100%); }
  100% { transform: translateX(-100%); }
 }
 
 /* Shaking subtitle effect*/
 @keyframes aniShake {
  0%, 33% { text-shadow: 3px -3px 0px #FE008E, -5px 5px 0px #00FFFF; }
  34%, 66% { text-shadow: 5px -5px 0px #FE008E, -3px 3px 0px #00FFFF; }
  67%, 100% { text-shadow: 3px -3px 0px #00FFFF, -5px 5px 0px #FE008E; }
 }

At this point, a handheld barrage function with shaking and scrolling effects has been realized.

The function is not complicated. At first, I thought about drawing it with canvas, but in the mini program, native components like canvas are at a relatively high level. If I want to switch special effects and write a pop-up window to modify the configuration, it is not easy. So I researched and wrote it in CSS3. I just want to say: "CSS3 is awesome!!!"

More configuration effect previews in the mini program

Recently, I made a small program, and added the handheld barrage function, and realized more functions. You can also share your configured content with friends. Welcome everyone to scan the code to experience it and support it...

insert image description here

Summary: This is my first time writing a blog. I spent the whole afternoon deleting and cutting. I am not very good at writing articles, but I still finished it. After all, people always have to learn to grow up on their own...

This is the end of this article about how to simply implement the handheld barrage function + text shaking special effects code based on JS. For more relevant js handheld barrage text shaking content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Example of video bullet screen effect implemented by JS
  • Realizing bullet screen special effects based on JavaScript
  • Simple implementation of JavaScript bullet screen effect
  • JavaScript live comment barrage cut picture function point collection effect code

<<:  Docker's health detection mechanism

>>:  Example of how to enable Brotli compression algorithm for Nginx

Recommend

CSS mimics remote control buttons

Note: This demo is tested in the mini program env...

Docker installs mysql and solves the Chinese garbled problem

Table of contents 1. Pull the mysql image 2. Chec...

How to prompt and open hyperlink a

<br />The countless information on the Inter...

A brief discussion on React Component life cycle functions

What are the lifecycle functions of React compone...

How many times will multiple setStates in React be called?

Table of contents 1. Two setState, how many times...

display:grid in CSS3, an introduction to grid layout

1. Grid layout (grid): It divides the web page in...

Free tool to verify that HTML, CSS and RSS feeds are correct

One trick for dealing with this type of error is t...

jQuery implements the mouse drag image function

This example uses jQuery to implement a mouse dra...

How to display a small icon in front of the browser URL

When you browse many websites, you will find that ...

Detailed installation and use of docker-compose

Docker Compose is a Docker tool for defining and ...

jQuery plugin to implement minesweeper game (1)

This article shares the specific code of the firs...

Sample code for implementing Google third-party login in Vue

Table of contents 1. Developer Platform Configura...

JavaScript Basics: Scope

Table of contents Scope Global Scope Function Sco...

Detailed explanation of MySQL high availability architecture

Table of contents introduction MySQL High Availab...

How to migrate the data directory in Docker

Table of contents View Disk Usage Disk Cleanup (D...