Facebook
From sea, 10 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 82
  1. var cards = document.querySelectorAll('.card');
  2.     var counters = [0, 0];
  3.     var targets = [100, 200];
  4.  
  5.     function startCount(index) {
  6.       var counterElement = cards[index].querySelector('.card-sayı');
  7.       counterElement.classList.add('show');
  8.  
  9.       var counter = counters[index];
  10.       var target = targets[index];
  11.  
  12.       var interval = setInterval(function() {
  13.         if (counter >= target) {
  14.           clearInterval(interval);
  15.         } else {
  16.           counter++;
  17.           counterElement.querySelector('.sayı-text').textContent = counter;
  18.         }
  19.       }, 10);
  20.     }
  21.  
  22.     var observer = new IntersectionObserver(function(entries, observer) {
  23.       entries.forEach(function(entry, index) {
  24.         if (entry.isIntersecting) {
  25.           startCount(index);
  26.           observer.unobserve(entry.target);
  27.         }
  28.       });
  29.     }, { threshold: 0.5 });
  30.  
  31.     cards.forEach(function(card) {
  32.       observer.observe(card);
  33.     });