Skip to content

Is it possible to add offset to enableScrollSpy? #305

Answered by stratboy
stratboy asked this question in Q&A
Discussion options

You must be logged in to vote

This is my working solution using just an intersectionObserver:

import { CountUp } from "countup.js";

const counters = document.querySelectorAll('.counters-block .counter-number');
var countups = [];

for(const counter of counters){
  const tovalue = parseInt(counter.dataset.tovalue, 10);  
  const countUp = new CountUp(counter.id, tovalue, { 
    // enableScrollSpy: true, 
    // scrollSpyDelay: 0,
    duration: 3
  });

  countups.push(countUp);
}


const counters_box = document.querySelector(".counters-box");

let counter_observer = new IntersectionObserver((entries, observer) => { 
  entries.forEach(entry => {
    if(entry.isIntersecting){
      for(const countup of countups) countup.s…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@stratboy
Comment options

Comment options

You must be logged in to vote
2 replies
@inorganik
Comment options

@stratboy
Comment options

Answer selected by stratboy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants