Anime.js: Grid layout causing issues with displaying simple text animations

I'm attempting to create a text animation within a grid layout using the anime.js library, but unfortunately, the animation isn't displaying. The project consists of just one HTML file.

The JavaScript code:

<script>

import anime from 'animejs';

anime({
  targets: 'container.decor1.HLF',
  translateY: [
    { value: 100, duration: 1200 },
    { value: 0, duration: 800 }
  ],
  duration: 2000,
  loop: true
});

</script>

The HTML elements intended for animation:

<div class = "container">
    <div class = "decor1">
        <p class = "HLF">
        HLF
        </p>
    </div>
</div>

Any suggestions on how to resolve this issue would be greatly appreciated. Thank you!

Complete code snippet provided below:

<!DOCTYPE html>

<html>
<head>
<script>

import anime from 'animejs';

anime({
  targets: 'container.decor1.HLF',
  translateY: [
    { value: 100, duration: 1200 },
    { value: 0, duration: 800 }
  ],
  duration: 2000,
  loop: true
});

</script>
</head>

<style>

.tweets {grid-area: tweets; background: rgb(240, 240, 240, 0.5); padding: 40px;
         margin: 15px; font-family: arial}
.quotes {grid-area: quotes; background: turquoise; padding: 20px;
         margin: 15px; font-family: helvetica; color: white; font-size: 20px}
.decor1 {grid-area: decor1; background: rgb(50, 50, 50, 0.5); padding: 5px;
         margin: 15px; font-family: helvetica; text-align: center}
.HLF { color: white; font-size: 200px; margin:1px}
.distributor { color: white; font-size: 20px; margin:1px}
.visual {grid-area: visual; background: rgb(0, 50, 200, 0.6); padding: 20px;
         margin: 10px; font-family: helvetica; font-size: 20px;
         border: none; border-radius: 10px; color: white}
.product {grid-area: product; background: rgb(35, 35, 35, 0.7); padding: 20px;
          margin: 10px; font-family: helvetica; font-size: 20px; border: none;
          border-radius: 10px; color: white}

.container {

    display: grid;
    grid-template-areas:
        'tweets quotes decor1'
        'tweets visual product';
    background-color: rgb(0, 100, 0, 0.8);
    padding: 100px;

    }

.quote-1, 
.quote-2, 
.quote-3 {
    animation-duration: 20s;
    animation-timing-function: ease-in-out;
    animation-iteration-count: infinite;
}

.quote-1{
    animation-name: quote-1;
}

.quote-2{
    animation-name: quote-2;
}

.quote-3{
    animation-name: quote-3;
}


</style>


<body style = "background: white">

<div class = "container">
    <div class = "tweets">
    <center>
    <a class="twitter-timeline" data-width="250" data-height="350" data-dnt="true" data-theme="dark" href="https://twitter.com/Herbalife24?ref_src=twsrc%5Etfw">Tweets by Herbalife24</a>
    <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script> 
    </center>
    </div>
    <div class = "quotes">
        <p class = "quote-1">
        "Our bodies consist of 65% water." 
        </p>
    <p class = "quote-2">
        "Our bodies consist of 65% water."
        </p>
    <p class = "quote-3">
        "Our bodies consist of 65% water."
        </p>
    </div>

    <div class = "decor1">
        <p class = "HLF">
        HLF
        </p>
        <p class = "distributor">
        Independent Distributor
        </p>    
    </div>

    <button class = "visual" onclick = "alert('Under Development')"> Visualization </button>
    <button class = "product"> Product </button>
</div>

</body>

</html>

Answer №1

There are a couple of important points to address:

  • The suggestions in the comments below your post regarding changes to the import statement are valid. I also had to adjust the import statement to reference a local version of anime.min.js:
<script src="js/anime.min.js"></script>
  • It's crucial to ensure that components are loaded by the DOM before attempting to script them. Therefore, I moved your anime script block to the bottom of the HTML page, as you originally had it positioned about five lines from the top.
  • I made a change to the target class to be .HLF as per your specification - however, it may be more appropriate to use an id instead in your HTML.
<script>
  anime({
    targets: '.HLF',
    translateY: [
      { value: 100, duration: 1200 },
      { value: 0, duration: 800 }
    ],
    duration: 2000,
    loop: true,
  });
</script>

As a result of these adjustments, the animation successfully executed!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

After the rendering process, the React Component member goes back to a state of

One issue I encountered is related to a component that utilizes a separate client for making HTTP requests. Specifically, when trying to use the client within a click event handler, the call to this.client.getChannel() fails due to this.client being undefi ...

Why does the video cover extend past its lower boundary in HTML?

I'm facing an issue where a purple cover over the <video> element extends slightly beyond the video's bottom border. Here's the code I'm using: .media-cover { display: inline-block; position: relative; } .media-cover:after ...

Modifying a single route among several nested routes with specific names

My template includes various named, nested views: Template 1: <body> <div ui-view></div> </body> Template 2: <header></header> <div ui-view="left"></div> <div ui-view="canva ...

Lines that are next to each other within an svg path and have a stroke

I'm working with an SVG that contains multiple lines within a path element. <path stroke-width="13" stroke="black" fill="orange" d="M 100 100 L 300 100 Z L200 300 z"/> Due to the stroke-width, the lines a ...

Adjusting the size of div content without changing its dimensions

I'm in search of a solution for resizing the contents within a fixed width and height div. Currently, my div looks like this: <div id="editor_preview" style="width:360px !important; color:gray; ...

Transmit HTML message using the "textarea" tag through email

Whenever I try to send the content of my "textarea" via email, it always ends up being sent as a blank message. How can I fix this issue? Below is my PHP code: <?php $input = json_decode(file_get_contents("php://input"), true); $ToEmail = "<a href ...

Angular version 4 is used to retrieve deeply nested JSON data

How do I extract data from a nested JSON file? Here is an example of the JSON structure: { "user1": { "name": "john", "surname": "johnsson" }, "user2": { "name": "Jacob", "surname": "Jacobsson" } } I want t ...

Node.js express version 4.13.3 is experiencing an issue where the serveStatic method is not properly serving mp3 or

I am currently utilizing Express 4.13.3 along with the serve-static npm module to serve static assets successfully, except for files with mp3 or ogg extensions. Despite reviewing the documentation, I have not come across any information indicating that thi ...

Looking for a way to prevent anonymous functions in jQuery using Greasemonkey?

Is there a way to prevent the execution of this particular jquery function? I've tried various scripts and even wrote my own, but nothing seems to work. $(document).ready(function () { $(window).on('beforeunload', function() { re ...

Cypress and Cucumber collaborate to reinitialize the requests within Next Js

In my upcoming project with Next.js, I am utilizing Cypress for testing a specific page. The objective is to validate two scenarios: 1. Successful outcome and 2. Error handling when a user encounters an issue. Before(() => { return void cy.server() ...

How can I turn off shadows for every component?

Is it feasible to deactivate shadows and elevation on all components using a configuration setting? ...

Is it possible to set a single Tailwind breakpoint that will automatically apply to all CSS styles below it?

Responsive design in Tailwind is achieved by using the following code snippet: <div className="sm: flex sm: flex-row sm: items-center"></div> It can be cumbersome to constantly include the sm: breakpoint for each CSS rule. I want ...

Sort activities according to the preferences of the user

This is the concept behind my current design. Click here to view the design When making a GET request, I retrieve data from a MongoDB database and display it on the view. Now, I aim to implement a filter functionality based on user input through a form. ...

Divide the canvas into 100 separate sections using Javascript

Help! I'm trying to divide a canvas into 100 squares that are 50x50px each, but my current code is becoming too lengthy with multiple for loops. Is there a more efficient way to achieve this with just one for loop? Below is the existing code snippet: ...

The HTML page is failing to call the function in the JavaScript application

I recently started taking a YouTube Javascript course on chapter 34 titled "Make start button work" Javascript tutorial My HTML, CSS, and Javascript files are all located in the same folder. I am using VS Code along with the Live Server extension for codi ...

Move the element that can be dragged with the identifier X to the designated drop area with the identifier

I am attempting to create a function that will allow me to drag a draggable element and drop it into a designated container using their IDs. However, I am unsure of how to get started. dropToContainer("myDraggable", "div3"); function dropToContainer(co ...

Emphasize the interactions within the table cells based on their corresponding column and row

I'm looking to achieve a specific interaction in my Angular Material table. I want to highlight the table cell interactions with column and row by extending the highlighting up to the column header and left to the row header. Is this something that ca ...

Tips for saving a PHP variable in an HTML attribute

I am working on a page that allows users to select colors from a list using checkboxes. When the user submits their selections, I want all the chosen colors to be displayed with their corresponding color as their font color. Below is the code I have so fa ...

How can you conceal an HTML element when the user is using an iOS device?

I need the code to determine if a user is using an iOS device and, if not, hide the HTML input type "Play" button. So, I'm uncertain whether my iOS detection is correct, the hiding of the "Play" button in the code, or both: <!DOCTYPE html> < ...

RxJS - Only emit if another source does not emit within a specified time frame

Imagine having two observables. Whenever the first one emits, there should be a 2-second pause to check if the other observable emits something within that timeframe. If it does, then no emission should occur. However, if it doesn't emit anything, the ...