ужасное поведение chrome - PullRequest
0 голосов
/ 20 июня 2020

код отлично работает с Microsoft Edge, но в Chrome секундная стрелка возвращается через секунду. Кажется, что переменная secondHand не изменяется при первом увеличении времени. Но всякий раз, когда я отлаживаю с помощью инструментов разработчика, он отлично работает. Есть ли какие-то проблемы с браузером, которые не отображаются должным образом?

    let hourHand = document.querySelector('.hour');
    let minuteHand = document.querySelector('.minute');
    let secondHand = document.querySelector('.second');

    let intialHourHandPosition = (new Date().getHours())*30-90;
    let intialMinuteHandPosition = (new Date().getMinutes())*6-90;
    let intialSecondHandPosition = (new Date().getSeconds())*6-90;

    hourHand.style.transform = `rotate(${intialHourHandPosition}deg)`;
    minuteHand.style.transform = `rotate(${intialMinuteHandPosition}deg)`;
    secondHand.style.transform = `rotate(${intialSecondHandPosition}deg)`;

    function timer(){
        hourHand.style.transform = `rotate(${intialHourHandPosition+=(30/3600)}deg)`;
        minuteHand.style.transform = `rotate(${intialMinuteHandPosition+=(6/60)}deg)`;
        secondHand.style.transform = `rotate(${intialSecondHandPosition+=6}deg)`;
    }
    setTimeout(()=>{secondHand.style.transition = 'transform 1s linear';
                    hourHand.style.transform = `rotate(${intialHourHandPosition+=(30/3600)}deg)`;
                    minuteHand.style.transform = `rotate(${intialMinuteHandPosition+=(6/60)}deg)`;
                    secondHand.style.transform = `rotate(${intialSecondHandPosition+=6}deg)`;
                    },0)
        
    setInterval(timer,1000)
*{
    width: 100%;
    height: 100%;
}
.clockContainer{
    top: 20%;
    width: 400px;
    height: 350px;
    margin:auto;
    position: relative;
}
.clockContainer img{
    width: 100%;
    height: 100%;
    display: block;
    box-shadow: 0 0 5px gray;
    border-radius: 50%;
}
.handHolder{
    height: 25px;
    width: 25px;
    border-radius: 50%;
    background-color: rgb(0, 0, 0);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-40%);
}
.hour{
    position: absolute;
    height: 10px;
    width: 20%;
    background-color: black;
    top: 50%;
    left: 50%;
    transform-origin: 0%;
    border-radius: 0 50% 50% 0;
}
.minute{
    position: absolute;
    height: 5px;
    width: 25%;
    background-color: rgb(0, 0, 0);
    top: 50%;
    left: 50%;
    transform-origin: 0%;
    border-radius: 0 50% 50% 0;

}
.second{
    position: absolute;
    height: 2px;
    width: 30%;
    top: 50%;
    left: 50%;
    transform-origin: 0%;
    background-color: black;
    border-radius: 0 50% 50% 0;
}                                       
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    
</head>
<body>

    <div class="clockContainer">
        <img src="clock.jpg" >
        <div class="handHolder"></div>
        <div class="hour"></div>
        <div class="minute"></div>
        <div class="second"></div>
    </div>

</body>
</html>
...