1

機関車のスクロールで要素が表示されているときに関数をトリガーする方法を誰か教えてもらえますか、私は初心者です、詳しく説明してください、事前に感謝します

  const counterFunc = () => {
 counters.forEach((counter) => {
const updateCount = () => {
  const target = +counter.getAttribute("data-target");
  const count = +counter.innerText;

  // Lower inc to slow and higher to slow
  const inc = target / speed;

  // console.log(inc);
  // console.log(count);

  // Check if target is reached
  if (count < target) {
    // Add inc to count and output in counter
    counter.innerText = count + inc;
    // Call function every ms
    setTimeout(updateCount, 1);
  } else {
    counter.innerText = target;
    }
 };
  updateCount();
});
 };

 //HTML
<div id="counter-SUBSCRIBERS">
          <h1 class="counter" data-scroll data-target="60000">0</h1>
          <h5>Subscribers</h5>
        </div>
        <div id="counter-VIDEOS">
          <h1 class="counter" data-target="15000">0</h1>
          <h5>Comments</h5>
        </div>
        <div id="counter-ENGAGEMENT">
          <h1 class="counter" data-target="9000">0</h1>
          <h5>Share</h5>
4

1 に答える 1