Contador Progressiva

Asked

Viewed 601 times

0

I’m trying to make a progressive counter in the style of the Impostometer, but it’s a non-monetary amount, just a unit. At the moment this is my code:

<html>
<head>
    <title>Teste Contador</title>
</head>
<script src="vendor/jquery.js"></script>
<body onload="startCountdown()">
    <?php
        date_default_timezone_set('America/Sao_Paulo');
        $n = 180000;
        $cur_time = time();
        $orig_time = strtotime("2019-02-18 9:00:00");
        $x = $n + ceil((abs(time() - strtotime("2019-02-18 9:23:00"))) / (533 + 1/3));
    ?>
    <script>
        var g_iCount = new Number();
        var g_iCount = <?= $x ?>;
        function startCountdown(){
            if((g_iCount - 1) >= 0){
                g_iCount = g_iCount + 1;
                numberCountdown.innerText = g_iCount;
                setTimeout('startCountdown()',1000);
            };
        };
    </script>
    <div class="numberCountdown">
        <div id="numberCountdown"></div>
    </div>
    <style>
        .numberCountdown {
            color: #0000ff;
        }
    </style>
</body>

The problems I’m facing are: 1- I would like not to use "onload='startCountdown()'" in the "body" tag; 2- I would like to place a filter of hundred, thousand, millions, etc.(123.456.789); Any lack of information just mention that I edit the post as soon as possible.

1 answer

0


  1. Just add the tag script after the divs

  2. Use match to be separated three by three and the join to unite with the .

Code:

<?php
    date_default_timezone_set('America/Sao_Paulo');
    $n = 180000;
    $cur_time = time();
    $orig_time = strtotime("2019-02-18 9:00:00");
    $x = $n + ceil((abs(time() - strtotime("2019-02-18 9:23:00"))) / (533 + 1/3));
?>
<div class="numberCountdown">
    <div id="numberCountdown"></div>
</div>
<style>
    .numberCountdown {
        color: #0000ff;
    }
</style>
<script>
    let g_iCount = <?php echo $x; ?>;
    function startCountdown(){
        if((g_iCount - 1) >= 0){
            g_iCount++;
            numberCountdown.innerText = g_iCount.toString().match(/[0-9]{1,3}/g).join('.');
            setTimeout(startCountdown, 1000);
        };
    };
    startCountdown();
</script>
  • For some reason he’s adding 2-in-2.

  • Edit1: It was my mistake, I was pulling the function twice.

  • If my answer solved your problem click the button next to it to accept it

Browser other questions tagged

You are not signed in. Login or sign up in order to post.