Html:
<!--Countdown area--
<div id= "Countdown" ></div>
CSS: (can be found on the site: jquery.countdown.css)
. countdownholder{
Width:15rem;
Height:1.6rem;
margin:0 Auto;
Font:1rem ' Open Sans condensed ', sans-serif;
Text-align:center;
letter-spacing:-3px;
}
. position{
Display:inline-block;
Height:1.6em;
Overflow:hidden;
position:relative;
Width:1.05em;
}
/* Color of the move */
. digit{
Position:absolute;
Display:block;
Width:1em;
Background-color: #ff5500;
Border-radius:0.2em;
Text-align:center;
Color: #fff;
letter-spacing:-1px;
}
. digit.static{
box-shadow:1px 1px 1px rgba (4, 4, 4, 0.35);
Background-image:linear-gradient (bottom, #3A3A3A 50%, #444444 50%);
Background-image:-o-linear-gradient (Bottom, #3A3A3A 50%, #444444 50%);
Background-image:-moz-linear-gradient (Bottom, #3A3A3A 50%, #444444 50%);
Background-image:-webkit-linear-gradient (Bottom, #3A3A3A 50%, #444444 50%);
Background-image:-ms-linear-gradient (Bottom, #3A3A3A 50%, #444444 50%);
/* font up/down color */
Background-image:-webkit-gradient (
Linear
Left Bottom,
Left Top,
Color-stop (0.5, #000),
Color-stop (0.5, red)
);
}
/**
* Can use these classes to hide parts
* of the countdown that you don ' t need.
*/
. countdays{/* Display:none!important;*/}
. countdiv0{/* Display:none!important;*/}
. counthours{}
. countdiv1{}
. countminutes{}
. countdiv2{}
. countseconds{}
. countdiv{
Display:inline-block;
width:16px;
Height:1.6em;
position:relative;
}
/* Color of Middle point */
. Countdiv:before,
. countdiv:after{
Position:absolute;
width:5px;
height:5px;
Background-color: #444;
border-radius:50%;
left:50%;
margin-left:-3px;
Top:0.5em;
box-shadow:1px 1px 1px rgba (4, 4, 4, 0.5);
Content: ";
}
. countdiv:after{
Top:0.9em;
}
JS: (4--1. Set top-level font size, cause set mobile REM
2. The introduction of jquery, the reason plug-in to use
3. Call the countdown plugin to download-jquery.countdown.js directly online
4. Set the countdown)
1.
<script type= "Text/javascript" >
(function () {
var html = document.documentelement;
var hwidth = Html.getboundingclientrect (). width;
Html.style.fontSize = hwidth/16 + "px";
Console.log (HWIDTH/16);
})();
</script>
2.
<!--introduction of jquery-->
<script src= "Http://code.jquery.com/jquery-1.7.1.min.js" ></script>
3.
/**
* @name JQuery Countdown Plugin
* @author Martin Angelov
* @version 1.0
* @url http://tutorialzine.com/2011/12/countdown-jquery/
* @license MIT License
*/
(function ($) {
Number of seconds in every time division
var days = 24*60*60,
Hours = 60*60,
minutes = 60;
Creating the Plugin
$.fn.countdown = function (prop) {
var options = $.extend ({
Callback:function () {},
timestamp:0
},prop);
var left, D, H, M, s, positions;
Initialize the Plugin
Init (this, options);
positions = This.find ('. Position ');
(function tick () {
Time left
left = Math.floor ((Options.timestamp-(New Date ()))/1000);
if (left < 0) {
left = 0;
}
Number of days left
D = Math.floor (left/days);
Updateduo (0, 1, D);
Left-= d*days;
Number of hours left
h = Math.floor (left/hours);
Updateduo (2, 3, h);
Left-= h*hours;
Number of minutes left
m = Math.floor (left/minutes);
Updateduo (4, 5, m);
Left-= m*minutes;
Number of seconds left
s = left;
Updateduo (6, 7, s);
Calling an optional user supplied callback
Options.callback (D, H, M, s);
Scheduling another call of this function in 1s
SetTimeout (tick, 1000);
})();
This function updates the digit positions at once
function Updateduo (minor,major,value) {
Switchdigit (Positions.eq (minor), Math.floor (VALUE/10)%10);
Switchdigit (Positions.eq (Major), value%10);
}
return this;
};
function init (elem, Options) {
Elem.addclass (' Countdownholder ');
Creating the markup inside the container
$.each ([' Days ', ' Hours ', ' Minutes ', ' Seconds '],function (i) {
$ (' <span class= ' count ' +this+ ' > '). html (
' <span class= ' position ' >\
<span class= "digit static" >0</span>\
</span>\
<span class= "Position" >\
<span class= "digit static" >0</span>\
</span> '
). AppendTo (Elem);
if (this!= "Seconds") {
Elem.append (' <span class= ' countdiv countdiv ' +i+ ' ></span> ');
}
});
}
Creates an animated transition between the and the numbers
function Switchdigit (position,number) {
var digit = Position.find ('. Digit ')
if (Digit.is (': Animated ')) {
return false;
}
if (position.data (' digit ') = = number) {
We is already showing this number
return false;
}
Position.data (' digit ', number);
var replacement = $ (' <span> ', {
' class ': ' Digit ',
css:{
Top: ' -2.1em ',
opacity:0
},
Html:number
});
The. Static class is added when the animation
Completes. This makes it run smoother.
Digit
. Before (replacement)
. Removeclass (' static ')
. Animate ({top: ' 2.5em ', opacity:0}, ' Fast ', function () {
Digit.remove ();
})
Replacement
. Delay (100)
. Animate ({top:0,opacity:1}, ' Fast ', function () {
Replacement.addclass (' static ');
});
}
}) (JQuery);
4.
$ (function () {
var note = $ (' #note '),
ts = new Date (2017, 3, 30,14),//month set minus one
NewYear = true;
if ((New Date ()) > ts) {
The New Year is here! Count towards something else.
Notice the *1000 at the End-time must is in milliseconds
TS = (new Date ()). GetTime () + 10*24*60*60*1000;
NewYear = false;
}
$ (' #countdown '). Countdown ({
Timestamp:ts,
Callback:function (days, hours, minutes, seconds) {
var message = "";
Message + + days + ' Day ' + (days==1? ': ' s ') + ",";
Message + = Hours + "Hour" + (hours==1? ': ' s ') + ",";
Message + = minutes + "minute" + (minutes==1? ': ' s ') + ' and ';
Message + = seconds + "second" + (seconds==1? ': ' s ') + "<br/>";
if (newyear) {
Message + = "Left until the new year!";
}
else {
Message + = "Left to ten days from now!";
}
note.html (message);
}
});
});
Countdown effects compatible with mobile and safary browsers