Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript random six digit number with animation

var numbers = [12, 54, 32, 45, 21, 69, 20];
function generateNumber(index) {
  var desired = numbers[index];
  var duration = 2000;

  var output = $('#output' + index); // Start ID with letter
  var started = new Date().getTime();

  animationTimer = setInterval(function() {
    if (output.text().trim() === desired || new Date().getTime() - started > duration) {
      clearInterval(animationTimer); // Stop the loop
      output.text(desired); // Print desired number in case it stopped at a different one due to duration expiration
      generateNumber(index + 1);
    } else {
      output.text(
        '' +
        Math.floor(Math.random() * 10) +
        Math.floor(Math.random() * 10)
      );
    }
  }, 100);
}

generateNumber(0);
Comment

javascript random six digit number with animation

.output {
    margin: 20px;
    padding: 20px;
    background: gray;
    border-radius: 10px;
    font-size: 80px;
    width: 80px;
    color: white;
    float: left;
}
Comment

javascript random six digit number with animation

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="output" id="output0">--</div>
<div class="output" id="output1">--</div>
<div class="output" id="output2">--</div>
Comment

PREVIOUS NEXT
Code Example
Javascript :: adonis select distinct inner join 
Javascript :: math.pow vs math.exp 
Javascript :: node ja sap concur 
Javascript :: react router not working with aws amplify 
Javascript :: riverSizes javascript 
Javascript :: how long does razor burn last 
Javascript :: show ingoing node on click cytoscape.js 
Javascript :: onclick show 10 elements 
Javascript :: reduce javascript acc became numeber insted array 
Javascript :: stub in javascript 
Javascript :: get each primary colour and add into an array javascript 
Javascript :: xjavascript 
Javascript :: mdn 
Javascript :: javascript linkify string text 
Javascript :: js remove plus 
Javascript :: window is null 
Javascript :: every character on your keyboard js 
Javascript :: how to get the data from clicking on notification on web in reactjs 
Javascript :: pg ssl settings js 
Javascript :: getcontext canvas not autocomplete 
Javascript :: is an array that is in sorted order a min-heap 
Javascript :: loop array 
Javascript :: xpath cheat sheet using node 
Javascript :: how to push an object into an array in reducer 
Javascript :: display prety html json data 
Javascript :: android studio select sim slot to send sms 
Javascript :: how to make kak in javascript 
Javascript :: 9.5. The Accumulator Pattern¶ 
Javascript :: component not registered correctly 
Javascript :: how to check if an image exists in js from cross origin 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =