question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'useGrouping' setting ignored on dynamically created countup

See original GitHub issue
[X] Bug
[ ] Feature request

CountUp.js version: 2.2.0

Description

Case: multiple instances created within an observer (‘enableScrollSpy’ was not compatible with another script). Grouping is by default active and that’s fine, except for 1 number, it needs to be disabled. The dynamic settings come from data-attributes and work fine so far. But only the ‘useGrouping’ setting is ignored. Tested: disabling grouping by default - works.

let countups = {};
let timeouts = {};
const counters = document.querySelectorAll(".number-item");
const countersObserver = new IntersectionObserver (function (entries, observer) {
	var i = 0;
	entries.forEach(function(entry) {
		if (entry.isIntersecting) {
			var	cid = entry.target.id
				cno = entry.target.dataset.number,
				suf = entry.target.dataset.suffix || "",
				time = entry.target.dataset.time || "2",
				sep = entry.target.dataset.sep || ".",
				grp = entry.target.dataset.group || true,
				opts = {
				'enableScrollSpy': false,
				'suffix': suf,
				'duration': time,
				'separator': sep,
				'useGrouping': grp
			}
			countups[entry.target.id]= new countUp.CountUp(cid, cno, opts );
			timeouts[entry.target.id] = setTimeout(() => {
				countups[entry.target.id].start();
			}, 0 + (500*i) );
			observer.unobserve(entry.target);
		}
		i++;
	},{});
});
counters.forEach ( function (countUpItems) {
	countersObserver.observe(countUpItems);
});

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
despecialcommented, Jun 20, 2022

A the last info was helpful. The check failed on the empy separator. Fixed it with: sep = (entry.target.dataset.sep==="") ? "" : ".", Removed the grouping data attribute and now it works as intended. Thanks!

Btw: countUp is awesome with data-attributes and many instances.

0reactions
inorganikcommented, Jun 20, 2022

Ok so I see this:

grp = entry.target.dataset.group || true,

The value of the attribute is string"false" and I don’t know if that’s coerced into a boolean or not. But even if it was you are doing grp = false || true which will set it to true.

Last, you are supposedly setting an empty separator, and CountUp will set useGrouping to false given an empty separator. So I don’t understand how you are interpreting that it is ignoring useGrouping when you’ve passed an empty separator?

Read more comments on GitHub >

github_iconTop Results From Across the Web

SOQL and SOSL Reference - Salesforce Implementation guides
Dynamic SOQL in Apex—Apex requires that you surround SOQL and SOSL ... Aggregate functions on page 53 in SOQL queries ignore null values, ......
Read more >
Spread for ASP.NET Developer's Guide - GrapeCity
This guide provides introductory conceptual material and how-to explanations for routine tasks for developers using. Spread for ASP.NET.
Read more >
by Bernd Klein - Python Courses eu
I created a basic syntax, used indentation for statement grouping instead of curly braces or begin-end blocks, and developed a small number of...
Read more >
Learning Targets - Findley Elementary
1-Phoemic Awareness : Identify initial, medial, and final sounds in a single syllable word. Count number of sounds in a syllable and count...
Read more >
Overview - Joe Sandbox
Created File. DNS/IP Info; Is Dropped; Is Windows Process; Number of created Registry Values; Number of created Files; Visual Basic; Delphi ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found