简体   繁体   中英

Show hidden div in javascript?

I have this countdown timer, and once it reaches 0, I want it to show div, which is currently set to: display: none;

Here is the countdown code:

function startTimer(duration, display) {
      var timer = duration,
          minutes, seconds;
      setInterval(function () {
        minutes = parseInt(timer / 60, 10)
        seconds = parseInt(timer % 60, 10);

        minutes = minutes < 10 ? "0" + minutes : minutes;
        seconds = seconds < 10 ? "0" + seconds : seconds;

        display.textContent = minutes + " min " + seconds + " sec";

        if (--timer < 0) {
            display.textContent = "Yay, It's done!"

      }

      }, 1000);
    }

    window.onload = function () {
          display1 = document.querySelector('#time1');

      startTimer(1 * 5, display1);
    };

At this part:

if (--timer < 0) {
    display.textContent = "Yay, It's done!"

how would I make it also show hidden div, after showing that text?

您可以将其显示设置为“阻止”。

elementYouWantToShow.style.display = 'block';

Plain JS

document.getElementById('myID').style.display = "block";

JQuery

$('#myID').fadeIn();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM