Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
| de:create:timer-display [01.07.2022 19:13] – alte Version wiederhergestellt (01.04.2017 17:26) admin | de:create:timer-display [16.04.2026 11:38] (aktuell) – [Countdown zeigen] admin | ||
|---|---|---|---|
| Zeile 122: | Zeile 122: | ||
| ===== Countdown zeigen ===== | ===== Countdown zeigen ===== | ||
| - | Es ist für die Teilnehmer u.U. irritierend, | + | Es ist für die Teilnehmer u.U. irritierend, |
| + | |||
| + | Die Zeit legen Sie hier in der letzten Code-Zeile fest. | ||
| <code javascript> | <code javascript> | ||
| <script type=" | <script type=" | ||
| <!-- | <!-- | ||
| + | |||
| + | function Countdown(duration, | ||
| + | let countdownTimer; | ||
| + | let countdownStart = Date.now(); | ||
| + | let countdownDisplay; | ||
| + | let running = false; | ||
| - | var countdown | + | function complete() { |
| - | var countdownDisplay; | + | // Display nextbutton |
| - | var countdownTimer; | + | |
| - | // " | + | |
| - | // mit " | + | // Remove countdown |
| - | var buttonID = " | + | button.parentNode.removeChild(countdownDisplay); |
| + | // Anything else to do? | ||
| + | if (callback) { | ||
| + | callback(); | ||
| + | } | ||
| + | } | ||
| - | function | + | |
| - | // Next button | + | // Next button |
| - | | + | |
| - | // Create countdown element | + | // Create countdown element |
| - | countdownDisplay = document.createElement(" | + | countdownDisplay = document.createElement(" |
| - | | + | |
| - | cd.style.display = " | + | cd.style.display = " |
| - | cd.style.textAlign = " | + | cd.style.textAlign = " |
| - | cd.style.fontWeight = " | + | cd.style.fontWeight = " |
| - | cd.style.width = button.offsetWidth + " | + | cd.style.width = button.offsetWidth + " |
| - | cd.style.height = button.offsetHeight + " | + | cd.style.height = button.offsetHeight + " |
| - | // Init countdown | + | // Init countdown |
| - | button.parentNode.appendChild(countdownDisplay); | + | button.parentNode.appendChild(countdownDisplay); |
| - | | + | |
| - | // Hide next button | + | // Hide next button |
| - | button.style.display = " | + | button.style.display = " |
| - | // Start countdown | + | } |
| - | countdownTimer = window.setInterval(countDown, | + | |
| - | } | + | |
| - | function | + | |
| - | if (countdown > 1) { | + | if (!running) { |
| - | | + | window.clearInterval(countdownTimer); |
| - | countdownRefresh(); | + | |
| - | } else { | + | } |
| - | | + | let timeLeft |
| - | // Display nextbutton | + | if (timeLeft <= 0) { |
| - | var button | + | running |
| - | | + | |
| - | // Remove countdown | + | |
| - | button.parentNode.removeChild(countdownDisplay); | + | return; |
| - | } | + | } |
| - | } | + | |
| - | function countdownRefresh() { | + | |
| - | | + | while (countdownDisplay.lastChild) { |
| - | while (countdownDisplay.lastChild) { | + | countdownDisplay.removeChild(countdownDisplay.lastChild); |
| - | countdownDisplay.removeChild(countdownDisplay.lastChild); | + | } |
| - | } | + | // Display |
| - | // Display | + | |
| - | | + | countdownDisplay.appendChild(content); |
| - | countdownDisplay.appendChild(content ); | + | } |
| - | } | + | |
| - | SoSciTools.attachEvent(window, | + | function start() { |
| + | // Start countdown | ||
| + | countdownTimer = window.setInterval(refresh, 200); | ||
| + | running = true; | ||
| + | } | ||
| + | window.addEventListener(" | ||
| + | window.addEventListener(" | ||
| + | } | ||
| + | |||
| + | // " | ||
| + | // mit " | ||
| + | new Countdown(30, | ||
| + | |||
| // --> | // --> | ||
| </ | </ | ||
| </ | </ | ||
| + | |||
| + | |||
| + | ---- | ||
| + | |||
| + | **Suchbegriffe: | ||