jq 获取当时时间的到秒_JS+jQuery显示开机时间(精确到秒)

该博客介绍了如何使用JS和jQuery显示开机时间并实现精确到秒的倒计时功能。通过绑定点击事件,利用animate方法进行动画效果,隐藏元素。同时,分享了JavaScript代码实现时间倒计时的逻辑,包括天数、小时、分钟和秒的计算,并动态更新显示。
摘要由CSDN通过智能技术生成

这次给大家带来JS+jQuery显示开机时间(精确到秒),JS+jQuery显示开机时间的注意事项有哪些,下面就是实战案例,一起来看一下。

实现原理:

给关闭按钮绑定点击事件,点击以后触发动画效果。利用jQuery的animate方法,先让显示天气的盒子高度变为0,接着让整个包含天气和事件的盒子宽度变为0,最后通过将display属性值设为none,使得close按钮消失。

实现代码:

仿360开机效果

*{

padding: 0;

margin: 0;

}

.box{

width: 320px;

position: fixed;

bottom: 0;

right: 0;

box-shadow: 1px 1px 10px #2d2d2d;

}

#close{

position: absolute;

top: 0;

right: 0;

width: 30px;

height: 20px;

cursor: pointer;

background-color: red;

color: pink;

font-weight: bold;

text-align: center;

}

.hd{

width: 320px;

height: 300px;

background-color: #03c03c;

color: #fff;

font-size: 70px;

line-height: 300px;

text-align: center;

}

.bd{

width: 320px;

height: 100px;

background-color: #fffc00;

font-size: 30px;

line-height: 100px;

text-align: center;

}

X

1分12秒

天气:晴天

window.onload = function(){

var close = document.getElementById("close");

var box = close.parentNode;

var b = document.getElementById("b");

// 给关闭按钮绑定点击事件

close.onclick = function(){

animate(b, {"height":0}, function(){

animate(box,{"width":0});

});

close.style.display = "none";

}

}

PS:JS 实现时间倒计时

var maxtime = 1350057600 //截止到的日期

var now=parseInt((new Date().getTime())/1000);//获取当前的日期

var cha_time=maxtime-now;//中间所差的时间

下面方法把相差的时间组合成倒计时的字符串,然后放到页面相应位置实现,实时刷新function CountDown(){

if(cha_time>=0){

var day = Math.floor(cha_time/3600/24);

var hour= Math.floor((cha_time/3600)%24);

var minutes = Math.floor((cha_time/60)%60);

var seconds = Math.floor(cha_time%60);

msg = "离结束还有"+day+"天"+hour+"小时"+minutes+"分"+seconds+"秒";

$(".ws_sg_con_big,.ws_sg_con_small").find("dd").html(msg);

--cha_time;

}

else{

clearInterval(timer);

alert("时间到,结束!");

}

}

timer = setInterval("CountDown()",1000);

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

推荐阅读:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值