Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Отсчет до нового года

Май
1
0
Пользователь
9781.jpg

HTML в виджет:
<div class="ny-countdown-widget">
    <div class="nyw-header">
        <i class="fas fa-tree nyw-icon"></i>
        <span>До Нового года осталось</span>
    </div>
    <div class="nyw-timer" id="nywTimer">
        <div class="nyw-block">
            <span class="nyw-num" id="nywDays">--</span>
            <span class="nyw-label">дней</span>
        </div>
        <div class="nyw-block">
            <span class="nyw-num" id="nywHours">--</span>
            <span class="nyw-label">часов</span>
        </div>
        <div class="nyw-block">
            <span class="nyw-num" id="nywMinutes">--</span>
            <span class="nyw-label">минут</span>
        </div>
        <div class="nyw-block">
            <span class="nyw-num" id="nywSeconds">--</span>
            <span class="nyw-label">секунд</span>
        </div>
    </div>
</div>

<script>
(function() {
    function getNewYear() {
        var now = new Date();
        var year = now.getFullYear();
        // Новый год — 1 января 00:00:00 следующего года
        var ny = new Date(year + 1, 0, 1, 0, 0, 0);
        // Если сейчас ещё не наступил этот НГ — берём текущий год+1,
        // если уже прошёл (например, 1 января) — автоматически следующий
        return ny;
    }

    function pad(n) {
        return n < 10 ? '0' + n : n;
    }

    function updateTimer() {
        var now = new Date();
        var ny = getNewYear();
        var diff = ny - now;

        if (diff <= 0) {
            document.getElementById('nywTimer').innerHTML =
                '<div class="nyw-holiday"><i class="fas fa-champagne-glasses"></i> С Новым годом!</div>';
            return;
        }

        var days = Math.floor(diff / (1000 * 60 * 60 * 24));
        var hours = Math.floor((diff / (1000 * 60 * 60)) % 24);
        var minutes = Math.floor((diff / (1000 * 60)) % 60);
        var seconds = Math.floor((diff / 1000) % 60);

        document.getElementById('nywDays').textContent = days;
        document.getElementById('nywHours').textContent = pad(hours);
        document.getElementById('nywMinutes').textContent = pad(minutes);
        document.getElementById('nywSeconds').textContent = pad(seconds);
    }

    updateTimer();
    setInterval(updateTimer, 1000);
})();
</script>


И

В extra less:
.ny-countdown-widget {
    background: linear-gradient(135deg, #8b0000 0%, #c62828 50%, #ff6f00 100%);
    border-radius: 12px;
    padding: 16px;
    color: #fff;
    text-align: center;
    box-shadow: 0 4px 15px rgba(139, 0, 0, 0.35);

    .nyw-header {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 10px;
        font-size: 15px;
        font-weight: 600;
        margin-bottom: 14px;
        text-transform: uppercase;
        letter-spacing: 0.5px;

        .nyw-icon {
            color: #ffd700;
            font-size: 20px;
            animation: nyw-bounce 2s ease-in-out infinite;
        }
    }

    .nyw-timer {
        display: flex;
        justify-content: space-around;
        gap: 8px;
    }

    .nyw-block {
        flex: 1;
        background: rgba(255, 255, 255, 0.15);
        border-radius: 8px;
        padding: 10px 4px;
        display: flex;
        flex-direction: column;
        backdrop-filter: blur(4px);
    }

    .nyw-num {
        font-size: 22px;
        font-weight: 700;
        color: #ffffff;
        line-height: 1.2;
    }

    .nyw-label {
        font-size: 10px;
        text-transform: uppercase;
        opacity: 0.85;
        margin-top: 4px;
    }

    .nyw-holiday {
        width: 100%;
        font-size: 18px;
        font-weight: 700;
        padding: 10px;

        i { color: #ffd700; margin-right: 6px; }
    }
}

@keyframes nyw-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

@media (max-width: 480px) {
    .ny-countdown-widget {
        .nyw-num { font-size: 16px; }
        .nyw-label { font-size: 9px; }
    }
}
 
Сверху