Search code examples
jquerycounterpage-refresh

Stop jQuery counterUp Plugin Script from Reloading


I'm using a simple counterUp script but when the columns of the website resize via media queries it is triggered again. Could anyone advise on the best way to run this and have it function just once without being retriggered unless the page is refreshed? Thanks!

<h3><span class="counter">457</span></h3>

$(document).ready(function() { //when document is ready
        $('.counter').counterUp({
            delay: 10,
            time: 1800
        });
    });

Fixed counterUp issue with the following:

$( window ).resize(function() { //Prevent being triggered again with window resize
        $('.counter').destroy();

    });

Solved! :)


Solution

  • Fixed counterUp issue with the following:

    $( window ).resize(function() { //Prevent being triggered again with window resize
            $('.counter').destroy();
    
        });
    

    Solved! :)