TRY AND ERRΦR

気になったこと、勉強したこと、その他雑記など色々メモしていきます。。Sometimes these posts will be written in English.,

Modified behavior of jquery plugins [Counter-Up] to effect at only first viewed.

I think this is the most fantastic plugin for increasing the number text dynamically.

Counter-Up/jquery.counterup.js at master · bfintal/Counter-Up · GitHub

But it's been getting a little old at recent, so there's a problem that the option named "triggerOnce" doesn't work.
The detail of the problem is that the count up effect occurs every time when display is scrolled into the element even though I set a "triggerOnce" option. Anyway, I hope that the effect occurs at just only the first time if I set that option into a initializer, so I fixed the problem to put below code into the jquery.counterup.js.

// Start the count up
setTimeout($this.data('counterup-func'), $settings.delay);
$this.attr("data-counterup_finished", true);    // Add

And

var counterUpper = function() {

    // Add start
    if ($this.data("counterup_finished") == true) {
        return false;
    }
    // Add end

    var nums = [];
    var divisions = $settings.time / $settings.delay;
    var num = $this.text();

    ...


It's the end.