html 固定某個時間替換圖片

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="HandheldFriendly" content="true"/>
        <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes"/>
        <title>優秀員工</title>
        <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
        <link rel="stylesheet" type="text/css" href="css/common.css?v=5" />
    </head>
    <body>
        <div class="container">
          <div class="itinerary-overview-content" id="itinerary-overview-img">
             
          </div>
        </div>
        <div class="to_top_btn"></div>
        <a class="retun-home" href="index.html"></a>
    </body>
    <script src="js/jquery-3.4.1.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/common.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript">
        $(function(){
            //獲取當前時間開始
            //var nowTime=getFormatDate();
            //function getFormatDate(){
              //var nowDate = new Date();
                //var year = nowDate.getFullYear();
                //var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
                //var date = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
                //var hour = nowDate.getHours()< 10 ? "0" + nowDate.getHours() : nowDate.getHours();
                //var minute = nowDate.getMinutes()< 10 ? "0" + nowDate.getMinutes() : nowDate.getMinutes();
                //var second = nowDate.getSeconds()< 10 ? "0" + nowDate.getSeconds() : nowDate.getSeconds();
               // return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second;
           // }
           // console.log(nowTime)
            //獲取當前時間結束
            // 獲取當前時間的時間戳
            var timestamp = Math.round(new Date().getTime()/1000);
            // 目標時間的時間戳
            var target_time = 1578365580;
            // 到目標時間自動切換圖片
            if(timestamp <= target_time){
                $('#itinerary-overview-img').html('<img class="content-img" src="https://eventimg.oss-cn-shenzhen.aliyuncs.com/annual_meeting/am_hotel_introduction_img.png" width="100%">')
            }else{
                $('#itinerary-overview-img').html('<img class="content-img" src="https://eventimg.oss-cn-shenzhen.aliyuncs.com/annual_meeting/am_excellent_staff_img.png" width="100%">')
            }
        })
        
    </script>
</html>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章