Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
en:create:timer-display [12.01.2016 09:27] – [Show Other Content] adminen:create:timer-display [12.01.2016 09:37] – Added countdown script admin
Line 95: Line 95:
  
  
-===== Placeholder for the Missing Button =====+===== Placeholder for the Button =====
  
 With this solution, the layout is slightly altered when the button appears -- the page gets bigger. If you do not want this, you can hide the content with the CSS attribute ''visibility'', instead of with ''display'': With this solution, the layout is slightly altered when the button appears -- the page gets bigger. If you do not want this, you can hide the content with the CSS attribute ''visibility'', instead of with ''display'':
Line 121: Line 121:
   }   }
 ); );
 +
 +// -->
 +</script>
 +</code>
 +
 +
 +===== Display Countdown =====
 +
 +It may be irritation for respondents if the "next" button is missing. Therefore, it may be useful to display a countdown instead. Use the following HTML/JavaScript code to do so:
 +
 +<code javascript>
 +<script type="text/javascript">
 +<!--
 +
 +var countdown = 30;
 +var countdownDisplay;
 +var countdownTimer;
 +// "submit0" is the next button,
 +// use "buttonsAuto" instead to include the back button as well
 +var buttonID = "submit0";  
 +
 +function countdownStart() {
 +  // Next button
 +  var button = document.getElementById(buttonID);
 +  // Create countdown element
 +  countdownDisplay = document.createElement("div");
 +  var cd = countdownDisplay;
 +  cd.style.display = "inline-block";
 +  cd.style.textAlign = "center";
 +  cd.style.fontWeight = "bold";
 +  cd.style.width = button.offsetWidth + "px";
 +  cd.style.height = button.offsetHeight + "px";
 +  // Init countdown
 +  button.parentNode.appendChild(countdownDisplay);
 +  countdownRefresh();
 +  // Hide next button
 +  button.style.display = "none";
 +  // Start countdown
 +  countdownTimer = window.setInterval(countDown, 1000);
 +}
 +
 +function countDown() {
 +  if (countdown > 1) {
 +    countdown--;
 +    countdownRefresh();
 +  } else {
 +    window.clearTimeout(countdownTimer);
 +    // Display nextbutton
 +    var button = document.getElementById(buttonID);
 +    button.style.display = "";
 +    // Remove countdown
 +    button.parentNode.removeChild(countdownDisplay);
 +  }
 +}
 +
 +function countdownRefresh() {
 +  // Clear
 +  while (countdownDisplay.lastChild) {
 +    countdownDisplay.removeChild(countdownDisplay.lastChild);
 +  }
 +  // Display
 +  var content = document.createTextNode(countdown + " sec.");
 +  countdownDisplay.appendChild(content );
 +}
 +
 +SoSciTools.attachEvent(window, "load", countdownStart);
  
 // --> // -->
 </script> </script>
 </code> </code>
en/create/timer-display.txt · Last modified: 12.08.2022 19:26 by admin
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Driven by DokuWiki