JavaScript与jQuery实现360风格开机倒计时动画
作者:窗边听雨时间:2026-10-22 09:43:01浏览:317
本文介绍如何利用JavaScript和jQuery实现仿360开机时间的显示效果。通过绑定关闭按钮点击事件,使用animate方法依次调整天气盒子高度及整体宽度,最终隐藏按钮。同时提供实时刷新倒计时的JS实现方案,计算剩余天数、小时、分钟和秒数并动态更新页面内容。
实现效果与原理
实现效果如下所示。

实现原理主要涉及交互逻辑与动画序列。
首先为关闭按钮绑定点击事件,用户点击后触发一系列动画。具体步骤为:利用jQuery的animate方法,先将显示天气的盒子高度设置为0;随后将整个包含天气和事件信息的盒子宽度设置为0;最后将display属性值设为none,使close按钮完全消失。
jQuery动画实现代码
具体实现代码如下。
<!DOCTYPE html>
<html>
<head>
<title>仿360开机效果</title>
<meta charset="utf-8">
<style type="text/css">
*{
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;
}
</style>
</head>
<body>
<div class="box">
<span id="close">X</span>
<div class="hd" id="t">1分12秒</div>
<div class="bd" id="b">天气:晴天</div>
</div>
<!-- 引入jQuery -->
<script type="text/javascript" src="./jquery1.0.0.1.js"></script>
<script type="text/javascript">
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";
}
}
</script>
</body>
</html>
JavaScript倒计时实现
补充说明:使用纯JS实现时间倒计时功能。
<script type="text/javascript">
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);
</script>
总结
以上介绍了基于javascript和jQuery实现的360开机时间显示效果,希望能为读者提供帮助。如有任何疑问,欢迎留言,小编会及时回复。感谢对本站的支持!
作者最新文章
anime.js 快速入门:怎么引入库并编写第一个 DOM 动画
2026-11-05 14:22:43
在线JS解密后变量名仍乱码?结合浏览器DevTools调试还原
2026-11-04 20:26:01
怎么在浏览器中运行JavaScript代码并查看输出结果
2026-11-04 09:07:33
JS 获取屏幕分辨率:window.screen.width 与 height 用法
2026-11-04 08:52:48
为什么推荐用DOMContentLoaded代替window.onload初始化JS
2026-11-04 08:42:33
