溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

javascript+jQuery如何實(shí)現(xiàn)360開(kāi)機(jī)時(shí)間顯示效果

發(fā)布時(shí)間:2021-06-24 14:48:19 來(lái)源:億速云 閱讀:127 作者:小新 欄目:web開(kāi)發(fā)

小編給大家分享一下javascript+jQuery如何實(shí)現(xiàn)360開(kāi)機(jī)時(shí)間顯示效果,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!

實(shí)現(xiàn)效果:

javascript+jQuery如何實(shí)現(xiàn)360開(kāi)機(jī)時(shí)間顯示效果

實(shí)現(xiàn)原理:

  給關(guān)閉按鈕綁定點(diǎn)擊事件,點(diǎn)擊以后觸發(fā)動(dòng)畫(huà)效果。利用jQuery的animate方法,先讓顯示天氣的盒子高度變?yōu)?,接著讓整個(gè)包含天氣和事件的盒子寬度變?yōu)?,最后通過(guò)將display屬性值設(shè)為none,使得close按鈕消失。

實(shí)現(xiàn)代碼:

<!DOCTYPE html>
<html>
<head>
 <title>仿360開(kāi)機(jī)效果</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");
  // 給關(guān)閉按鈕綁定點(diǎn)擊事件
  close.onclick = function(){
   animate(b, {"height":0}, function(){
    animate(box,{"width":0});
   });
   close.style.display = "none";
  }
 }
</script>
</body>
</html>

PS:JS 實(shí)現(xiàn)時(shí)間倒計(jì)時(shí)

<script type="text/javascript">
var maxtime = 1350057600 //截止到的日期
var now=parseInt((new Date().getTime())/1000);//獲取當(dāng)前的日期
var cha_time=maxtime-now;//中間所差的時(shí)間

下面方法把相差的時(shí)間組合成倒計(jì)時(shí)的字符串,然后放到頁(yè)面相應(yīng)位置實(shí)現(xiàn),實(shí)時(shí)刷新

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 = "離結(jié)束還有"+day+"天"+hour+"小時(shí)"+minutes+"分"+seconds+"秒"; 
$(".ws_sg_con_big,.ws_sg_con_small").find("dd").html(msg);
--cha_time; 
} 
else{ 
clearInterval(timer); 
alert("時(shí)間到,結(jié)束!"); 
} 
} 
timer = setInterval("CountDown()",1000); 
</script>

看完了這篇文章,相信你對(duì)“javascript+jQuery如何實(shí)現(xiàn)360開(kāi)機(jī)時(shí)間顯示效果”有了一定的了解,如果想了解更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI