jQuery_倒數器

In this example below you will see how to do a jQuery_倒數器 with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by mrjohnson, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright mrjohnson ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>jQuery_倒數器</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <div class="timeoutWrap">
  <div class="innerBox"></div>
  <ul class="numberChoice">
    <li class="active">5</li>
    <li>10</li>
    <li>15</li>
    <li>30</li>
    <li>60</li>
  </ul>
  <div class="clear"></div>
  <button class="start"></button>
</div>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/mrjohnson/jquery_andx5012andx6578andx5668-QmgQVr */
* {
  box-sizing: border-box;
}

.clear {
  both: clear;
}

.timeoutWrap {
  background: #374051;
  width: 320px;
  height: 480px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin-top: 20px;
  overflow: hidden;
}

.timeoutWrap:before,
.timeoutWrap:after {
  content: "";
  display: inline-block;
  position: absolute;
  height: 100%;
  width: 20%;
  z-index: 1;
}

.timeoutWrap:before {
  left: 0;
  background: linear-gradient(to right, #374051, transparent);
}

.timeoutWrap:after {
  right: 0;
  background: linear-gradient(to left, #374051, transparent);
}

.numberChoice {
  margin: 0;
  padding: 0;
  position: absolute;
  left: 33.3%;
  list-style: none;
  font-weight: bold;
  color: #fff;
  white-space: nowrap;
  transition: all 0.5s;
}

.numberChoice li {
  display: inline-block;
  /*   width:33.3%; */
  width: 103px;
  font-size: 56px;
  text-align: center;
  cursor: pointer;
  opacity: 0.5;
  transition: all 0.5s;
  position: relative;
}

.numberChoice li.active {
  opacity: 1;
  z-index: 999;
  -webkit-transform: scale(1.5);
  transform: scale(1.5);
}

.numberChoice li:first-child {
  margin-left: 0;
}

/* .timeoutWrap span {
  font-size: 56px;
  position: absolute;
  font-weight: bold;
  color: #fff;
  opacity: 0.8;
  display: inline-block;
}
.timeoutWrap span.cen {
  z-index: 10;
  font-size: 96px;
  opacity: 1;
}
.timeoutWrap span.left {
  left: 0;
}
.timeoutWrap span.right {
  right: 0;
} */

button {
  position: absolute;
  bottom: 32px;
  width: 48px;
  height: 48px;
  background: #fe6e6e;
  border: none;
  border-radius: 50%;
  transition: all 0.3s;
}

button:before,
button:after {
  content: "";
  display: inline-block;
  width: 48px;
  height: 48px;
  background: #fff;
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 50%;
  opacity: 0.8;
  -webkit-transform: scale(0);
  transform: scale(0);
  transition: all 0.3s;
}

button.active:before {
  opacity: 0;
  -webkit-transform: scale(1.8);
  transform: scale(1.8);
}

button:after {
  -webkit-transform: scale(1);
  transform: scale(1);
  background: #fe6e6e;
  opacity: 0;
}

button.active:after {
  background: #374051;
  opacity: 1;
}

.innerBox {
  display: none;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100%;
  background: #ff6d6e;
  z-index: 10;
  transition-timing-function: linear;
  -moz-transition-timing-function: linear;
  -webkit-transition-timing-function: linear;
  -o-transition-timing-function: linear;
  /*   transition:height .3s; */
}


/*Downloaded from https://www.codeseek.co/mrjohnson/jquery_andx5012andx6578andx5668-QmgQVr */
var height = 100;
var oriSecText
var secText;
var sec;
// $("button.start").click(function() {
//   var conutSecText = setInterval(function(){$(".timeoutWrap span.cen").text(secText=secText-1);},1000)
//   $(".timeoutWrap .innerBox").show(function() {
//     $(this).css({ "transition-duration": sec + "s", height: 0 });
//     setTimeout(function() {
//       $(".timeoutWrap .innerBox").css({ height: "100%", display: "none" });
//       $(".timeoutWrap span.cen").text(30);
//       secText = 30;
//       clearInterval(conutSecText);
//     }, 1000 * sec);
//   });
// });

$(".numberChoice li").click(function(){
  $(this).addClass("active").siblings().removeClass("active");
  leftMoveNumber = 103-($(this).index()*103);
  $(".numberChoice").css("left",leftMoveNumber);
})

$("button.start").click(function() {
  $(this).addClass("active");
  oriSecText=$(".numberChoice li.active").text();
  secText=$(".numberChoice li.active").text();
  sec=$(".numberChoice li.active").text();
  var conutSecText = setInterval(function(){$(".numberChoice li.active").text(secText=secText-1);},1000)
  $(".timeoutWrap .innerBox").show(function() {
    var startSec = .2;
    $(this).css({ "transition-duration": startSec + "s", height: "100%"});
    $(this).on("transitionend", function(event) {
        $(this).css({ "transition-duration": sec-startSec + "s", height: 0}); 
    });
    setTimeout(function() {
      $(".timeoutWrap .innerBox").css({ height: 0, display: "none" });
      $(".numberChoice li.active").text(oriSecText);
      $("button.start").removeClass("active");
      secText = oriSecText;
      clearInterval(conutSecText);
    }, 1000 * sec);
  });
});

Comments