兼容移动端以及safary浏览器 的倒计时特效

html:

<!--倒计时区域--><div id="countdown"></div>

css:(可在网站查找: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;}/*动时颜色*/.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%);   /*字体上下颜色*/   background-image: -webkit-gradient(      linear,      left bottom,      left top,      color-stop(0.5, #000),      color-stop(0.5, red)   );}

/** * You 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;}/*中间点的颜色*/.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.设置顶级字体大小,原因设置移动端rem

      2.引入jquery,原因插件要用到

3.调用倒计时插件,可在网上直接下载-jquery.countdown.js

4.设置倒计时)

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.

<!--引入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 two 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 two numbers   function switchDigit(position,number){

var digit = position.find(‘.digit‘)

if(digit.is(‘:animated‘)){         return false;      }

if(position.data(‘digit‘) == number){         // We are 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),//月份设置时减一      newYear = true;   if((new Date()) > ts){      // The new year is here! Count towards something else.      // Notice the *1000 at the end - time must be 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 10 days from now!";         }

note.html(message);      }   });

});
				
时间: 2024-08-12 08:37:30

兼容移动端以及safary浏览器 的倒计时特效的相关文章

原生JavaScript 导出excel表格(兼容ie和其他主流浏览器)

因同事的需求是想前端导出excel表格,网上找了一些demo,自己修改了一下,可能以后会用到,记录下来吧,兼容ie和一些主流浏览器,ie可能会报错,原因参考 这里,edge 浏览器还没有办法导出,正在尝试... <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>table 导出excel表格</title>

一个Ajax的XMLHttpRequest的open方法实例(只能兼容IE10及以上的浏览器)

Ajax的XMLHttpRequest的open方法 <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>浏览器通过JS控制输入的地址参数不同获取服务器内容(只能兼容IE10及以上的浏览器)</title>    <style>        body{font-family: '宋体';

分享个人博客皮肤【兼容移动端】

我真正开始写博客也有一年了,记得最开始写博客之前做的第一件事就是自定义皮肤样式,还为此写过一篇博文<博客园页面设置>.当然从现在的我看那个时候的我是那么的菜,也许一年之后看现在的我也会同样的想法(其实这样也挺好的,证明自己进步了).为什么要自定义皮肤样式?当然是为了编写出来的博文让人更有阅读欲,自己看着也舒服.很多时候没有一个好的皮肤样式也会成为我们不写博文的一个借口<我们为什么应该坚持写博客>. 其实,很多时候我是很懒的.不是实在看不下去了一般我也不会去动原来的样式.早就有写这篇

兼容ie5-ie11及其他主流浏览器的js document.getElementsByClassName 方法

var getElementsByClassName = function(searchClass,node,tag) { if(document.getElementsByClassName){ return document.getElementsByClassName(searchClass) }else{ node = node || document; tag = tag || '*'; var returnElements = [] var els = (tag === "*&quo

Jquery判断离开页面时,通过Ajax更新数据(兼容IE,Chrome,FF浏览器)

现在很多项目都有客户离开网页时,处理一些业务的需求.所以焦点就聚集在了如何获取页面离开事件. 以下是本人在一个项目中需要记录页面浏览时长的处理办法,测试兼容IE,Chrome,FF浏览器 代码如下: <!DOCTYPE html> <html> <head> <script type="text/javascript"> $(window).bind('beforeunload', function(e) {//页面卸载,就是用户关闭页面

MarkdownPad2代码高亮插件兼容移动端样式

如果不知道MarkdownPad2使用代码高亮插件可以查看前一篇文章<MarkdownPad2使用代码高亮插件> 先看移动端效果图: 移动端点击查看效果 或者手机扫如下二维码: 我们经常阅读微信公众号文章的时候,常常看到文章内有高亮的代码,并且这代码不会换行,可以左右拖动滚动这样的效果对于我们阅读代码很方便也很舒服,上一篇文章使用高亮插件并不兼容移动端,经过简单的对高亮代码样式得修改,再通过markdownpad2导出html,这样我们就可以在移动端查看自己的代码笔记了.这个时候有人会纳闷我在

服务端控制各种浏览器禁止缓存页面资源 学习笔记

import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class Demo2 extends HttpServlet { public voi

基于jQuery个性圆圈倒计时特效

基于jQuery个性圆圈倒计时特效里面包含十几款不用效果的jQuery倒计时特效下载.效果图如下: 在线预览   源码下载 实现的代码. html代码: <section class="header"> <div style="padding:20px;"><div id="rC"></div></div> </section> <div id="rC_A&q

js手机端浮层控件,并有多种弹出小提示,兼容pc端浏览器

js dialog组件,包含alert和confirm的实现 本组件所有的资源均在github上可以查看源代码 GitHub 本dialog的组件的例子请在这里查看 demo dialog js dialog弹窗 用法 这是内容 <input type="button" id="btn_dialog" value="打开浮层"/> <div id="dialog-content" style="di