Number Rolling Animation

How can I create a dynamic animation for a winning score in JavaScript?

I'm looking to increase the target number incrementally when the game is won

Here's my code snippet:

let firstTarget = 0;

And here's the JSX code:

<div
    style={{ backgroundColor: gameLost ? failureOp : gameWon ? successOp : 'lightgray' }}
    ref={firstNodeRef}
    className="inner-target-child"
>
    <div id="counter" className="animated">
        <ul className="digits luckie">
            <li>{firstTarget}</li>
            <li>{firstTarget + 1}</li>
            <li>{firstTarget + 2}</li>
            <li>{firstTarget + 3}</li>
        </ul>
    </div>
</div>

Additionally, here's the CSS code for the animation:

#counter {
   height: 1em;
   overflow: hidden;
}

.digits {
   float:center;
   list-style-type: none;
   font-size: 1em;
   line-height: 1em;
   margin-top: 0em;

   animation-duration: 2s;
   animation-timing-function: ease;
   animation-delay: 2.2s;
   animation-fill-mode: forwards;
}

.luckie {
   animation-name: luckie;
}

/* Animations */
@keyframes luckie {
   100% {
       margin-top: -3em;
   }
} 

Answer №1

Z-Template, a innovative client-side JavaScript library, allows for dynamic HTML rendering using a unique syntax that combines dynamic variables, conditionals, and loops. This library is MIT licensed, making it easy to integrate into your projects. By utilizing the provided zcall.roller.js file, you can take advantage of all the features Z-Template has to offer.

Implementing the entire library is as simple as:

<script type="text/javascript">zTemplate(document.querySelector('h1'), {"counter": 582});</script>
<h1 z-var="counter call roller">000</h1>

Check out this live demo on CodePen: https://codepen.io/webdevelopers/full/vYabQNL

For a closer look at the code library, visit: https://github.com/webdevelopers-eu/z-template/tree/master/javascript/extra

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

Align Inline Typography Component to the right in Material UI v5

After upgrading to MUI Version 5.4, I noticed that my Inline Typography no longer aligns correctly. In the previous version (MUI Version 4), this code worked fine: <Grid container xs={12}> <Grid container xs={12} justify="space-between&quo ...

Centering text using CSS Bootstrap

Hey everyone, I've been attempting to center my text using Bootstrap, but for some reason it's not working. Can someone help me figure out what's going on? <footer class="row p-1 mt-3 bg-primary text-white"> <p class= ...

The onclick attribute on a button in HTML is not functioning properly following the inclusion of an Ajax load

I am facing an issue with a button that is being dynamically loaded from PHP code using Ajax. The button has an onclick attribute that calls a function named viewImage. The Ajax request is triggered every 5 seconds inside the loadImages function. Snippet ...

Code for Rotating the Wheel - MINUS javascript

Exploring the possibility of creating a spin the wheel effect like this using only HTML and CSS, no Javascript involved Seeking references or examples to determine feasibility. ...

Is it better to use scale.set() or simply increase the size of the model in Three.js?

When it comes to scaling 3D models in Three.js (or any other 3D renderers), what is considered the best practice? Recently, I encountered a situation where I loaded a model only to realize that its size was too small. In order to adjust the size, I used m ...

Kindly attach the npm-debug.log file along with your support inquiry

When I try to use the "watch" command, I encounter the following error: "Please include the following file with any support request: C:\wamp\www\chandco\wp-content\themes\chandco\npm-debug.log". Below are the files in q ...

Create two dropdown menus using React and update the state of other input fields

Having two select-lists where the second select is dependent on the first selected object, causing mathematical calculations to disable inputs that should display the result. These inputs should always reflect the latest calculation based on the selected v ...

Mastering Sprite Movement in JavaScript: Going Forward with Your Sprite

Currently, I am developing a JavaScript game that utilizes the canvas functionality in HTML 5. I am looking to create projectiles that are capable of moving towards a specific coordinate by using a vector2 (x, y) as the velocity. Is there a mathematical fo ...

Having trouble retrieving the location property from an object obtained through an API request

Upon retrieving a task using its id after scanning a barcode, I successfully obtain the id and the data associated with the task. However, I am encountering an issue where I am unable to properly utilize the setLocation function with the resultData. When I ...

What are the steps to downloading a server-generated image with user data from the client using Express?

I am facing a challenge with downloading a server-generated image immediately after it is created. My current approach involves using fetch to send user input data (bypassing HTML forms). Although the image is successfully generated on the server, I am str ...

Unusual Characteristics of Synchronous Ajax Requests in JavaScript

First and foremost, I'd like to apologize if my approach seems unconventional. My background is primarily in C development, so I tend to tackle AJAX issues in a way that reflects my experience in C programming. The scenario at hand involves a script ...

Asynchronous function nested within a loop

Hello there! I am currently working on converting a SQLite database to NeDb using the following code snippet: const sqliteJSON = require('sqlite-json'); const Datastore = require('nedb') const exporter = sqliteJSON('etecsa.db&apo ...

Inconsistent display of Bootstrap tooltip upon mouseover

Utilizing an icon from Font Awesome to showcase text in a tooltip upon mouseover with Bootstrap, I encountered an issue where the tooltip only displays when hovering over the left half of the icon. This discrepancy occurs on both Edge and Chrome browsers, ...

Does the padding and margin of an element alter when the position is set to relative?

By utilizing relative positioning, an element can be moved in relation to its original position in normal flow. - Citation from the book "HTML&CSS: design and build websites" by John Duckett If an element has a relative position property, it opens up ...

Finding and removing the last portion of the innerHTML can be achieved by employing specific techniques

Looking to manipulate a <div> element that includes both HTML elements and text? You're in luck. I need to locate and remove either the last, nth-from-last, or nth plain text section within it. For example: <div id="foo"> < ...

Error encountered while using a vue js template

I have recently started learning vue.js and I am using it to dynamically update a list of <li> elements based on the selection from another list using vue.js. I'm encountering an error message that says: vue.js:465 [Vue warn]: Error compiling t ...

Determine the Ratio by comparing shared keys within an array of dictionaries

Looking to create a function that can calculate ratios based on specific keys and control which keys are eligible for ratio calculation. num = [{"HCOName":8919,"timestamp":"2019-01-01T00:00:00.000Z","Territory":"USA"}, {"HCOName":8275,"timestamp":" ...

What is the method to obtain the value of a <select> element using JavaScript?

How can I extract and transmit data using PHP? I am able to retrieve values from text input, but struggling with other types of input like select dropdowns. My goal is to send these values via email through a combination of AJAX and PHP. Here is the HTML ...

How to extract just the year from Material-UI's date picker in React

const displayYearOnly = (date) => { const year = date.getFullYear(); console.log(year); }; return ( <div style={{ marginRight: "20px" }}> <LocalizationProvider dateAdapter={AdapterDayjs}> <DemoContainer componen ...

Using JSON in Highcharts: Customizing Border and Label Colors

Currently using Highcharts in JSON format with the following syntax: var neutral_color = '#c4c4c4', medium_grey = '#929292'; lineChartJSON['chart']['plotBorderColor'] = medium_grey; lineChartJSON['chart&ap ...