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

Ways to retrieve the page name where the script originates from

I have a function that is triggered from three different pages. Each page involves adding an attribute to a specific div. For instance: <div id="posts" page="home"></div> <div id="posts" page="feed"></div> <div id="posts" page= ...

Adding an image to a jQuery class name on the fly

I am attempting to add an image before a div by using its className with jQuery. function insertImage(obj) { var dynamicClass = $(obj).prop("className"); After retrieving the classname, I now encapsulate it in single quotes and add a dot to access t ...

Creating unique CSS classes for custom forms in Web2py

What is the best way to assign a custom web2py form's class? for example: {{=form.custom.begin}} Image name: <div>{{=form.custom.widget.name}}</div> Image file: <div>{{=form.custom.widget.file}}</div> Click here to upload: {{= ...

Customizing the output format of Ng Date Picker beyond the standard ISO-8601

Just to clarify, I'm talking about a specific DatePicker component that can be found at the following link: Although the DatePicker interface is user-friendly and visually appealing, I'm facing an issue with the way it outputs values. While ther ...

Having an issue with discord.js and node.js modules not exporting correctly? The returned statement is not functioning as

Trying to retrieve specific messages from a channel to gather information about registered 'clans' has been quite challenging for me. I am able to fetch the channel, filter and loop through the messages, but strangely, I cannot return the fetched ...

Ensure that all divs have the same height and padding when resizing

I have 3 divs nested within a parent div. My goal is to dynamically set the height of all the child divs to match the height of the div with the maximum height, even when the screen resizes due to responsiveness. Below is my HTML structure: <div class ...

Changing Highcharts Donut Chart Title Text via Legend Item Click in React

Utilizing React. In my Highcharts donut chart, there are 5 legend items of type 'number' and a 'title text' (also type: number) displayed at the center. The title text represents the sum of all the legend items. However, when I click o ...

What could be causing the Express server to return an error despite everything being in order?

I am new to exploring express.js and attempting to create a basic sign-in example server. I have set up a database object with a users array containing objects, each with email and password properties. Despite using body-parser to convert the body into a j ...

Incorporate a background image property using Jquery

Can anyone help me with adding the css background-image:url("xxxxx") property to my code? jQuery('#'+$trackID+' .sc_thumb').attr('src',$thumb_url); jQuery('#'+$trackID+' .sc_container').css('display& ...

How to Route in Angular 5 and Pass a String as a Parameter in the URL

I am currently working on an Angular project that focuses on geographic system data. The concept is as follows: I have a component with the route: {path: 'home'}. I aim to pass a geojson URL along with this route, making it look like this: {pat ...

Issue with Bootstrap 3: Element refuses to remain within the defined width of the div container

While utilizing bootstrap 3 within a small div, I noticed that when I enlarge the window by dragging it horizontally, the fields (username and password input fields) that should remain inside the div end up shifting towards the center of the window. Can an ...

Tips on customizing KendoUI-Dialog titlebar using CSS for a single component

I am struggling with styling the KENDO UI dialog in a unique way: Imagine I have a component named WatComponent. Inside this component, When the user clicks the "Forbidden" button, my goal is to make a warning styled dialog appear, with a yellow/orange ...

Runtime Error: Invalid source property detected - Firebase and Next.js collaboration issue

Currently, I am developing a Next.js application that retrieves data from a Firestore database. The database connection has been successfully established, and the data is populating the app. However, I am facing an issue with displaying the image {marketpl ...

Creating a map in Typescript initialized with a JSON object

In my Typescript class, there is a map that I'm trying to initialize: public map:Map<string,string>; constructor() { let jsonString = { "peureo" : "dsdlsdksd" }; this.map = jsonString; } The issue I'm encounte ...

Is there a way to link table A's ID to table B's userID in a postgreSQL database?

Is it possible in PostgreSQL to establish a relational index between table A ID and table B userId for the purpose of joining two tables based on their ids? To provide further clarification, here is an example using MongoDB and Mongoose: const Billing = ...

What is the best place to define data that remains constant?

In a Vue component, I am looking to utilize data that remains constant. The issue arises when attempting to implement the following code: const numbers = [1, 2, 3] new Vue({ el: "#app" }) <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2 ...

Press the button to switch between displaying one component and hiding another component within reactjs

I am working on a project with two distinct buttons: one for grid view and another for list view. <button onClick={() => setClassName('jsGridView')} title="Grid View" > <IoGrid className="active" s ...

Craft an engaging and dynamic Image map with SVG technology to elevate responsiveness and interactivity

I'm currently working on a website and I need to create two clickable sections on the home page. Each section will lead to a different specialization of the company. To achieve this, I decided to use a square image split into two right-angled triangle ...

What are the steps for including and excluding components in Parallax JS?

When working with Parallax JS: I am trying to modify the components within the <li> tags of my menu, but I am unsure how to do so without restarting the plugin. I cannot seem to find the destroy command. Currently, I am using the JQuery version of ...

The multiple lines text box displays an input box

Having a simple issue here, I've set the value of an input text box, but when the page loads it is displaying in multiple lines, and this seems to be happening only on Chrome browser. Can anyone offer any assistance? This is the HTML code for the ...