Friday, March 31, 2023

Make a Amazing Clock: Unlocking the Power of HTML CSS and JavaScript #shorts #programming 😱😱

Make a Amazing Clock: Unlocking the Power of HTML CSS and JavaScript #shorts #programming 😱😱








<!-- Created by Siraj Tech Solution  -->



<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Clock 2</title>


    <style>/* Siraj Tech Solution */



* {

    padding: 0 ;

    margin: 0 ;

    box-sizing: border-box ;

    outline: none ;

    user-select: none ;

}


html {

    font-family: sans-serif ;

    -webkit-tap-highlight-color:#00000000;

}


.light-theme {

    --background : #FFDC89 ;

    --clock-body-color : #ffffff ;

    --on-clock-body-color : #5eaaa8 ;


    --clock-labels-color : #5eaaa8 ;

    --big-clock-labels-color : #056676 ;


    --hour-hand-color: #91d18b ;

    --minute-hand-color: #ffbd69 ;

    --second-hand-color: #ED6D79 ;

}


.dark-theme {

    --background : #1b262cf5 ;

    --clock-body-color : #1b262c;

    --on-clock-body-color : #00bcd4 ;


    --clock-labels-color : #5eaaa8 ;

    --big-clock-labels-color : #056676 ;


    --hour-hand-color: #91d18b ;

    --minute-hand-color: #ffbd69 ;

    --second-hand-color: #e11d74 ;

}


.wrapper {

    position: absolute ;

    width : 100vw ;

    height: 100vh ;

    top : 0 ;

    left: 0 ;


    display: flex ;

    align-items: center ;

    justify-content: center ;

    flex-direction: column ;


    background-color: var(--background) ;

}


.clock-container {

    --clock-size : 80vmin ;


    position: relative ;

    width : var(--clock-size);

    height: var(--clock-size) ;

}


.clock-container .clock-body {

    --label-margin :1.5rem;


    position: relative ;

    width : 100% ;

    height: 100% ;

    border-radius: 50% ;


    background-color: var(--clock-body-color) ;


    transition: background-color 200ms ease-out ;

    box-shadow: 0 4px 12px rgba(0,0,0,.05) , 0 2px 4px rgba(0,0,0,.1);

}


.clock-container .clock-body::before {

    position: absolute ;

    top : 50% ;

    left: 50% ;

    width : 90% ;

    height: 90% ;


    border-radius: 50% ;

    border:2px solid var(--on-clock-body-color);


    transform: translate(-50%,-50%);


    content: "" ;

}


.clock-container .clock-body .clock-labels {

    position: absolute ;

    width : 100% ;

    height: 100% ;


    color: var(--clock-labels-color);

}


.clock-container .clock-body .clock-labels .clock-label-row {

    --label-angle : 90deg ;

    position: absolute ;

    top : 50% ;

    left: 50% ;

    height: 100% ;

    width: 4ch ;

    font-size: 1rem ;

    line-height: 1rem ;


    display: flex ;

    flex-direction: column ;

    align-items: center ;

    justify-content: space-between ;


    padding: var(--label-margin) 0 ;


    transform: translate(-50%,-50%) rotate(var(--label-angle));

}


.clock-container .clock-body .clock-labels .big .top-label ,

.clock-container .clock-body .clock-labels .big .bottom-label {

    transform: rotate(calc(var(--label-angle) * -1)) ;

    font-size: 1.25rem ;

    font-weight: 500 ;

}


.clock-container .clock-body .clock-labels .clock-label-row:nth-of-type(1) {

    --label-angle:0deg;

}

.clock-container .clock-body .clock-labels .clock-label-row:nth-of-type(2) {

    --label-angle:30deg;

}

.clock-container .clock-body .clock-labels .clock-label-row:nth-of-type(3) {

    --label-angle:60deg;

}

.clock-container .clock-body .clock-labels .clock-label-row:nth-of-type(4) {

    --label-angle:90deg;

}

.clock-container .clock-body .clock-labels .clock-label-row:nth-of-type(5) {

    --label-angle:120deg;

}

.clock-container .clock-body .clock-labels .clock-label-row:nth-of-type(6) {

    --label-angle:150deg;

}


.clock-container .clock-body  .clock-hands {

    position: absolute ;

    width : 100% ;

    height: 100% ;


    z-index: 1 ;

}


.clock-container .clock-body .clock-hands::before {

    position: absolute ;

    top: 50% ;

    left: 50% ;

    width: 0.5rem ;

    height: 0.5rem ;

    content: "" ;

    border-radius: 50% ;


    background-color: var(--clock-body-color);

    border: 2px solid var(--second-hand-color);


    transition: background-color 200ms ease-out ;


    z-index: 1 ;


    transform:translate(-50%,-50%);

}


.clock-container .clock-body .clock-hands .clock-second-hand {

    --hand-length: calc(42.5% - var(--label-margin)) ;

    --hand-timeperiod : 60s ;

    --hand-tail-length : 1rem ;

    --hand-width:0.15rem;


    background-color: var(--second-hand-color) ;

}


.clock-container .clock-body .clock-hands .clock-minute-hand {

    --hand-length: calc(37.5% - var(--label-margin)) ;

    --hand-timeperiod : 3600s ;

    --hand-tail-length : 0.75rem ;

    --hand-width:0.25rem;


    background-color: var(--minute-hand-color) ;

}


.clock-container .clock-body .clock-hands .clock-hour-hand {

    --hand-length: calc(27.5% - var(--label-margin)) ;

    --hand-timeperiod  : 43200s ;

    --hand-tail-length : 0.5rem ;

    --hand-width:0.35rem;


    background-color: var(--hour-hand-color) ;

}



.clock-container .clock-body .clock-hands .clock-hour-hand ,

.clock-container .clock-body .clock-hands .clock-minute-hand ,

.clock-container .clock-body .clock-hands .clock-second-hand{

    position: absolute ;

    top : calc(50% - var(--hand-length) + var(--hand-tail-length));

    left: calc(50% - var(--hand-width) / 2);

    width: var(--hand-width) ;

    height: calc(var(--hand-length) + var(--hand-tail-length));


    transform-origin: 50% calc(100% - var(--hand-tail-length) * 2) ;

    transform: rotate(0deg);


    border-radius: calc(var(--hand-width) * 0.5);


    animation: clock-hand-motion var(--hand-timeperiod) steps(60) infinite;

}


@keyframes clock-hand-motion {

    from{

        transform: rotate(0deg);

    }

    to {

        transform: rotate(360deg);

    }

}


.clock-container .clock-body .clock-markings {

    position: absolute ;

    width: 100% ;

    height: 100% ;

}


.clock-container .clock-body .clock-markings .mark {

    position: absolute ;

    top : 50% ;

    left: 50% ;

    width : 2ch ;

    height: 100% ;


    transform: translate(-50%,-50%) rotate(0deg);

}


.clock-container .clock-body .clock-markings .mark::before {

    position: absolute ;

    top : calc(var(--label-margin)*2.25) ;

    left: 50% ;

    content: "" ;

    width : 0.2rem ;

    height: 0.2rem ;

    border-radius: 50% ;


    background-color: var(--on-clock-body-color);


    transform: translate(-50%,-50%);

}


.clock-container .clock-body .clock-name-label {

    position: absolute ;

    left  : 50% ;

    bottom: 30% ;


    color: var(--clock-labels-color);

    font-size: 0.8rem ;

    font-weight: 300 ;

    letter-spacing: 2px ;

    text-align: center ;


    opacity: 0.75 ;


    transform: translateX(-50%);

}


.theme-switch-container {

    position: relative ;

    width : 60vmin ;

    height: 20vmin ;


    margin-top:3rem;

    display: flex ;

    align-items: center ;

    justify-content: center ;

}


.theme-switch-container .theme-switch {

    position: relative ;

    width : 8rem ;

    height: 3rem ;


    border-radius: 3rem ;


    background-color: var(--clock-body-color);


    transition: background-color 200ms ease-out;


    overflow: hidden ;

}


.theme-switch-container .theme-switch .slide-group {

    position: absolute ;

    display: flex ;


    transition: transform 200ms ease-out ;

}


.theme-switch-container .theme-switch .slide-group .label {

    width : 5rem ;

    height: 3rem ;


    font-size: 0.8rem ;

    font-weight: 500 ;

    letter-spacing: 2px ;


    color: #454545 ;


    display: flex ;

    align-items: center ;

    justify-content: center ;

}


.theme-switch-container .theme-switch .slide-group .dark-mode {

    color: #eee;

}


.theme-switch-container .theme-switch .slide-group .switch-btn {

    position: relative ;

    width : 2.6rem ;

    height: 2.6rem ;

    flex: 0 0 2.6rem;

    margin: 0.2rem ;


    overflow: hidden ;

    background-color: #ffffff ;

    border-radius: 50% ;


    box-shadow: 0 2px 4px rgba(0,0,0,.1);


    cursor: pointer ;

}


.theme-switch-container .theme-switch .slide-group .switch-btn .icon{

    position: absolute ;

    top : 0 ;

    left: 0 ;

    width : 100% ;

    height: 100% ;


    display: flex ;

    align-items: center ;

    justify-content: center ;


    transition: opacity 200ms ease-out;


    opacity: 0 ;

}


.theme-switch-container .theme-switch .slide-group .switch-btn .icon svg {

    width : 50% ;

    height: 50% ;


    stroke: none ;

    fill: #454545 ;

}


.theme-switch-container .theme-switch[data-state="dark-mode"] {

    background-color:#1b262c ;

}


.theme-switch-container .theme-switch[data-state="dark-mode"] .slide-group .switch-btn .moon-icon{

    opacity: 1 ;

}


.theme-switch-container .theme-switch[data-state="light-mode"] .slide-group .switch-btn .sun-icon{

    opacity: 1 ;

}


.theme-switch-container .theme-switch[data-state="light-mode"] {

    background-color: #f5f5f5 ;

}


.theme-switch-container .theme-switch[data-state="light-mode"] .slide-group {

    transform: translateX(-5rem);

}</style>

    <script> 



window.onload = () => {

    generateClockMarkings();

    intializeClockTime();

};


function intializeClockTime(){

    let currentTime = new Date() ;


    // get current time in seconds

    let seconds = currentTime.getSeconds() ;

    let minutes = currentTime.getMinutes() ;

    let hours   = currentTime.getHours() ;


    // calculate Offsets based on passed time

    let secondHandOffset = seconds;

    let minuteHandOffset = minutes * 60 + seconds;

    let hourHandOffset   = hours * 3600 + minuteHandOffset ;


    // Apply offsets to clock hands

    let secondHand = document.querySelector(".clock-second-hand") ;

    let minuteHand = document.querySelector(".clock-minute-hand") ;

    let hourHand   = document.querySelector(".clock-hour-hand") ;


    secondHand.style.animationDelay = (-secondHandOffset) + "s" ;

    minuteHand.style.animationDelay = (-minuteHandOffset) + "s" ;

    hourHand.style.animationDelay   = (-hourHandOffset) + "s" ;

}


// this function generates markings 

function generateClockMarkings() {

    let markingContainer = document.querySelector(".clock-markings");


    for(var i=0;i<360;i+=6) {

        markingContainer.innerHTML += `<div class="mark" style="transform: translate(-50%,-50%) rotate(${i}deg);opacity:${i%30==0?0.75:0.3};"></div>` ;

    }


}


let darkModeEnabled = false ;

let bodyElement = null ;

let themeSwitch = null ;

// function to change theme

function switchTheme() {

    if(themeSwitch === null) 

        themeSwitch = document.getElementById("theme-switch");

    if(bodyElement === null)

        bodyElement = document.querySelector("body") ;

    

    if(darkModeEnabled === true) {

        themeSwitch.setAttribute("data-state","light-mode") ;

        bodyElement.classList.remove("dark-theme");

        bodyElement.classList.remove("light-theme");

        bodyElement.classList.add("light-theme");

        darkModeEnabled = false ;

    } else {

        themeSwitch.setAttribute("data-state","dark-mode") ;

        bodyElement.classList.remove("dark-theme");

        bodyElement.classList.remove("light-theme");

        bodyElement.classList.add("dark-theme");

        darkModeEnabled = true ;

    }


}

</script>

</head>

<body class="light-theme">

    <div class="wrapper">

        <div class="clock-container">

            <div class="clock-body">

                <div class="clock-markings">


                </div>

                <div class="clock-labels">

                    <div class="clock-label-row big">

                        <div class="top-label">12</div>

                        <div class="bottom-label">6</div>

                    </div>

                    <div class="clock-label-row">

                        <div class="top-label">|</div>

                        <div class="bottom-label">|</div>

                    </div>

                    <div class="clock-label-row">

                        <div class="top-label">|</div>

                        <div class="bottom-label">|</div>

                    </div>

                    <div class="clock-label-row big">

                        <div class="top-label">3</div>

                        <div class="bottom-label">9</div>

                    </div>

                    <div class="clock-label-row">

                        <div class="top-label">|</div>

                        <div class="bottom-label">|</div>

                    </div>

                    <div class="clock-label-row">

                        <div class="top-label">|</div>

                        <div class="bottom-label">|</div>

                    </div>

                </div>

                <div class="clock-hands">

                    <div class="clock-hour-hand"></div>

                    <div class="clock-minute-hand"></div>

                    <div class="clock-second-hand"></div>

                </div>

                <div class="clock-name-label">

                    <div class="name">! Quartz</div>

                </div>

            </div>

        </div>

    

        <div class="theme-switch-container">

            <div class="theme-switch" id="theme-switch" data-state="light-mode">

                <div class="slide-group">

                    <div class="dark-mode label">Dark</div>

                    <div class="switch-btn" onclick="switchTheme()">

                        <div class="moon-icon icon">

                            <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><path d="M12 24C5.367 24 0 18.633 0 12 0 5.488 5.152.285 11.477.012a.741.741 0 01.742.515.747.747 0 01-.293.856A8.25 8.25 0 0016.5 16.5a8.178 8.178 0 005.93-2.516.752.752 0 01.898-.136c.293.16.45.496.371.824A12.006 12.006 0 0112 24zM9.098 1.902A10.476 10.476 0 001.5 12c0 5.79 4.71 10.5 10.5 10.5 4.086 0 7.676-2.3 9.41-5.82A9.663 9.663 0 0116.5 18c-5.375 0-9.75-4.375-9.75-9.75a9.73 9.73 0 012.348-6.348zm0 0"/><path d="M19.5 9a.75.75 0 01-.75-.75c0-1.652-1.348-3-3-3a.75.75 0 010-1.5c1.652 0 3-1.348 3-3a.75.75 0 011.5 0c0 1.652 1.348 3 3 3a.75.75 0 010 1.5c-1.652 0-3 1.348-3 3a.75.75 0 01-.75.75zm-1.266-4.5c.5.332.934.766 1.266 1.266A4.54 4.54 0 0120.766 4.5 4.54 4.54 0 0119.5 3.234 4.54 4.54 0 0118.234 4.5zm0 0M14.25 14.672a.75.75 0 01-.75-.75c0-1.035-.84-1.875-1.875-1.875a.75.75 0 010-1.5c1.035 0 1.875-.84 1.875-1.875a.75.75 0 011.5 0c0 1.035.84 1.875 1.875 1.875a.75.75 0 010 1.5c-1.035 0-1.875.84-1.875 1.875a.75.75 0 01-.75.75zm-.508-3.375c.188.148.36.32.508.508.148-.188.32-.36.508-.508a3.122 3.122 0 01-.508-.508c-.148.188-.32.36-.508.508zm0 0"/></svg>

                        </div>

                        <div class="sun-icon icon">

                            <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><path d="M16.254 7.746A6.052 6.052 0 0012 5.97a5.923 5.923 0 00-4.254 1.777A6.052 6.052 0 005.97 12c0 1.652.699 3.176 1.777 4.254A6.052 6.052 0 0012 18.03a5.923 5.923 0 004.254-1.777A6.052 6.052 0 0018.03 12a5.923 5.923 0 00-1.777-4.254zm-1.145 7.363A4.374 4.374 0 0112 16.383a4.374 4.374 0 01-3.11-1.274A4.374 4.374 0 017.618 12c0-1.207.477-2.316 1.274-3.11A4.374 4.374 0 0112 7.618c1.207 0 2.316.477 3.11 1.274A4.374 4.374 0 0116.382 12a4.374 4.374 0 01-1.274 3.11zm0 0M23.176 11.176H20.73a.837.837 0 00-.824.824c0 .445.38.824.824.824h2.446A.84.84 0 0024 12a.84.84 0 00-.824-.824zm0 0M12 19.906a.837.837 0 00-.824.824v2.446A.84.84 0 0012 24a.84.84 0 00.824-.824V20.73a.837.837 0 00-.824-.824zm0 0M20.477 19.332l-1.747-1.746c-.285-.316-.824-.316-1.144 0a.809.809 0 000 1.144l1.746 1.747a.809.809 0 101.145-1.145zm0 0M12 0a.84.84 0 00-.824.824V3.27c0 .445.379.824.824.824a.837.837 0 00.824-.824V.824A.84.84 0 0012 0zm0 0M20.508 3.523a.809.809 0 00-1.145 0L17.617 5.27a.809.809 0 000 1.144c.29.316.828.316 1.145 0l1.746-1.746a.809.809 0 000-1.145zm0 0M3.27 11.176H.824A.84.84 0 000 12c0 .445.348.824.824.824H3.27A.837.837 0 004.094 12a.837.837 0 00-.824-.824zm0 0M6.383 17.586c-.29-.316-.828-.316-1.145 0l-1.746 1.746a.809.809 0 101.145 1.145l1.746-1.747a.809.809 0 000-1.144zm0 0M6.383 5.27L4.637 3.523a.809.809 0 10-1.145 1.145l1.746 1.746A.809.809 0 106.383 5.27zm0 0"/></svg>

                        </div>

                    </div>

                    <div class="light-mode label">Light</div>

                </div>

            </div>

        </div>

    </div>

</body>

</html>

No comments:

Post a Comment