Показать сообщение отдельно
  #12 (permalink)  
Старый 12.04.2020, 12:52
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,109

таймер время работы магазина
Сергей Ракипов,

<!DOCTYPE html>
<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">
</head>
<body>
  <div id="work_schedule">
    <p id="current_time" class="line"></p>
    <p id="hours" class="line"></p>
    <p id="dot" class="line">:</p>
    <p id="minutes" class="line"></p>
    <p id="statys"></p>
    <p id="remains"></p>
  </div>
  <script>
   // JavaScript Document
   let hours;
   let minutes;
   let time;
   let dot = document.getElementById("dot");
   dot.style.color = "black";
   let currentTime = document.getElementById("current_time");
   let hoursInput = document.getElementById("hours");
   let minutesInput = document.getElementById("minutes");
   let statys = document.getElementById("statys");
   let remains = document.getElementById("remains");
   let hoursOpen = 8;
   let hoursClose = 20;
   let oneMinuts = 0;
   let rezult_1 = "";
   let rezult_2 = "";
   let endingHour = "";
   let endingHour_2 =["с", "са", "сов"];
   let endingMinut = "";
   let endingMinut_2 =["a", "ы"];
   let open = "До отрытия ";
   let close = "До закрытия ";
   let openClose = "";
   function sec() {
     if(dot.style.color == "black") {
       dot.style.color = "white";
     }
     else {
       dot.style.color = "black";
     }
   }
   setInterval(sec, 1000);
   function openCloseStatys() {
     if(time < hoursOpen * 60) {
       statys.innerHTML = `Закрыто`;
       statys.style.backgroundImage = "url('close.png')";
       openClose = open;
       time = hoursOpen * 60 - time;
     }
     else if(time >= hoursClose * 60) {
       statys.innerHTML = `Закрыто`;
       statys.style.backgroundImage = "url('close.png')";
       openClose = open;
       time = hoursOpen * 60 + 24 * 60 - time;
     }
     else {
       statys.innerHTML = `Открыто`;
       statys.style.backgroundImage = "url('open.png')";
       openClose = close;
       time = hoursClose * 60 - time
     }
   }
   function timeHours() {
     rezult_1 = Math.floor(time / 60);
   }
   function timeMinuts() {
     rezult_2 = time % 60;
   }
   function timeZero(num) {
     if(num < 10) {
       num = "0" + num;
     }
     return num
   }
   function endingHourFun() {
     if(rezult_1==1) {
       endingHour = endingHour_2[0];
     }
     else if(rezult_1>=2&&rezult_1<=4) {
       endingHour = endingHour_2[1];
     }
     else if(rezult_1 == 0 ||rezult_1>=5&&rezult_1<=23) {
       endingHour = endingHour_2[2];
     }
   }
   function endingMinutFun() {
     if(rezult_2==1) {
       endingMinut = endingMinut_2[0];
     }
     else if(rezult_2>=2&&rezult_2<=4) {
       endingMinut = endingMinut_2[1];
     }
     else if(rezult_2>=5&&rezult_2<=20) {
       endingMinut = endingMinut;
     }
     else if(rezult_2==21) {
       endingMinut = endingMinut_2[0];
     }
     else if(rezult_2>=22&&rezult_2<=24) {
       endingMinut = endingMinut_2[1];
     }
     else if(rezult_2>=25&&rezult_2<=30) {
       endingMinut = endingMinut;
     }
     else if(rezult_2==31) {
       endingMinut = endingMinut_2[0];
     }
     else if(rezult_2>=32&&rezult_2<=34) {
       endingMinut = endingMinut_2[1];
     }
     else if(rezult_2>=35&&rezult_2<=40) {
       endingMinut = endingMinut;
     }
     else if(rezult_2==41) {
       endingMinut = endingMinut_2[0];
     }
     else if(rezult_2>=42&&rezult_2<=44) {
       endingMinut = endingMinut_2[1];
     }
     else if(rezult_2>=45&&rezult_2<=50) {
       endingMinut = endingMinut;
     }
     else if(rezult_2==51) {
       endingMinut = endingMinut_2[0];
     }
     else if(rezult_2>=52&&rezult_2<=54) {
       endingMinut = endingMinut_2[1];
     }
     else if(rezult_2>=55&&rezult_2<=60) {
       endingMinut = endingMinut;
     }
   }
   function loop()
   {
     let localTime = new Date;
     hours = localTime.getHours();
     minutes = localTime.getMinutes();
     time = hours * 60 + minutes;
     openCloseStatys();
     timeHours();
     timeMinuts();
     endingHourFun();
     endingMinutFun();
     currentTime.innerHTML = `Текущие время`;
     hoursInput.innerHTML = `${timeZero(hours)}`;
     minutesInput.innerHTML = `${timeZero(minutes)}`;
     remains.innerHTML = `${openClose}${timeZero(rezult_1)} ча${endingHour} ${timeZero(rezult_2)} минут${endingMinut}`;
     window.setTimeout(loop, 1000);
   }
   loop()
  </script>
</body>
</html>
Ответить с цитированием