Untitled

mail@pastecode.io avatar
unknown
plain_text
18 days ago
1.9 kB
2
Indexable
Never
------------- HTML ----------------

<div class="fixed bottom-0 w-full bg-[#58428c] text-white py-2 px-4 justify-center items-center z-10">
  <p class="text-xl font-bold text-center">
    Oferta limitowana! Tylko dla
    <span id="countdown" class="text-2xl animate-pulse">
      9
    </span>
    klientów.
  </p>
</div>
<div id="customerInfoContainer" class="fixed bottom-16 right-4 z-20 flex flex-col space-y-4">
</div>



--------- JavaScript --------------

<script>

const customerInfoContainer = document.getElementById('customerInfoContainer');
const countdownElement = document.getElementById('countdown');
const availableSlots = 9;
let currentSlots = availableSlots;

function updateCounter() {
  if (currentSlots > 0) {
    const randomTime = Math.floor(Math.random() * 25000) + 10000;
    setTimeout(() => {
      currentSlots--;
      updateCountdownDisplay();
      showCustomerInfo();
      updateCounter();
    }, randomTime);
  }
}

function updateCountdownDisplay() {
  countdownElement.textContent = currentSlots;
}

function showCustomerInfo() {
  const names = ['Adam', 'Bartosz', 'Cezary', 'Damian', 'Emil', 'Filip', 'Grzegorz', 'Hubert', 'Igor', 'Jakub'];
  const randomName = names[Math.floor(Math.random() * names.length)];
  const initial = String.fromCharCode(Math.floor(Math.random() * 26) + 65);

  const customerInfo = document.createElement('div');
  customerInfo.className = 'bg-[#58428c] text-white shadow-lg rounded-lg p-4 text-lg font-semibold animate-fade-in-down';
  customerInfo.textContent = `${randomName} ${initial}. właśnie kupił produkt!`;

  customerInfoContainer.appendChild(customerInfo);

  setTimeout(() => {
    customerInfo.classList.add('animate-fade-out');
    setTimeout(() => {
      customerInfoContainer.removeChild(customerInfo);
    }, 1000);
  }, 5000);
}

updateCountdownDisplay();
updateCounter();

</script>
Leave a Comment