亚洲一级黄色视频免费观看_国产亚洲精品综合在线网站_亚洲Av无码精品一区二区三区_特级无码一区二区三区毛片

主頁(yè) > 知識庫 > 基于HTML5+CSS3實(shí)現簡(jiǎn)單的時(shí)鐘效果

基于HTML5+CSS3實(shí)現簡(jiǎn)單的時(shí)鐘效果

熱門(mén)標簽:使用U盤(pán)裝系統 硅谷的囚徒呼叫中心 阿里云 美圖手機 檢查注冊表項 百度競價(jià)點(diǎn)擊價(jià)格的計算公式 智能手機 網(wǎng)站建設

目的:

利用html5,css實(shí)現鐘擺效果

知識點(diǎn):

1) 利用position/left/top和calc()實(shí)現元素的水平和垂直居中;

2) 利用CSS3的animation/transform/transform-origin屬性定義動(dòng)畫(huà);

3) 利用transform-origin實(shí)現旋轉原點(diǎn)的圓心調整

廢話(huà)不多說(shuō)了,直接看代碼吧,具體代碼如下所示:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        li{
            list-style:none;
        }
        #box{
            width: 400px;
            height: 400px;
            position: absolute;
            top:calc(50% - 200px);
            left:calc(50% - 200px);
            border: 2px solid palegoldenrod;
        }
        #dial{
            width: 200px;
            height: 200px;
            position: absolute;
            top:calc(50% - 100px);
            left:calc(50% - 100px);
            border: 2px solid cyan;
            border-radius: 50%;
        }   
        .scaleIndex{
            width: 4px;
            height: 12px;
            position: absolute;
            top: 0;
            left: calc(50% - 2px);
            background-color: gray;
            transform-origin: 2px 100px;
        }
        .angle30{transform : rotate(30deg);}
        .angle60{transform : rotate(60deg);}
        .angle90{transform : rotate(90deg);}
        .angle120{transform : rotate(120deg);}
        .angle150{transform : rotate(150deg);}
        .angle180{transform : rotate(180deg);}
        .angle210{transform : rotate(210deg);}
        .angle240{transform : rotate(240deg);}
        .angle270{transform : rotate(270deg);}
        .angle300{transform : rotate(300deg);}
        .angle330{transform : rotate(330deg);}
        #fixPoint{
            width: 10px;
            height: 10px;
            position: absolute;
            top:calc(50% - 5px);
            left:calc(50% - 5px);
            background-color: cadetblue;
            border-radius: 50%;
        }
        #hourHand{
            width: 6px;
            height: 70px;
            position:absolute;
            top: 40px;
            left: calc(50% - 3px);
            background-color: darkblue;
            transform-origin: 50% 60px;
        }
        #minuteHand{
            width: 4px;
            height: 75px;
            position:absolute;
            top: 35px;
            left: calc(50% - 2px);
            background-color: yellow;
            transform-origin: 50% 65px;
        }
        #secondHand{
            width: 2px;
            height: 90px;
            position:absolute;
            top: 20px;
            left: calc(50% - 1px);
            background-color: red;
            transform-origin: 50% 80px;
        }
    </style>
</head>
<body>
    <div id = "box">
            <div id = 'dial'>
                <ul id = "scale">
                    <li class = "scaleIndex"></li>
                    <li class = "scaleIndex angle30"></li>
                    <li class = "scaleIndex angle60"></li>
                    <li class = "scaleIndex angle90"></li>
                    <li class = "scaleIndex angle120"></li>
                    <li class = "scaleIndex angle150"></li>
                    <li class = "scaleIndex angle180"></li>
                    <li class = "scaleIndex angle210"></li>
                    <li class = "scaleIndex angle240"></li>
                    <li class = "scaleIndex angle270"></li>
                    <li class = "scaleIndex angle300"></li>
                    <li class = "scaleIndex angle330"></li>
                </ul>
                <div id = "fixPoint"></div>
                <div id = "hourHand"></div>
                <div id = "minuteHand"></div>
                <div id = "secondHand"></div>
            </div>
        </div>
<script type = 'text/javascript' src = 'js/jquery-3.2.1.js'></script>
<script type = "text/javascript">
window.onload = function(){
            var hourHand = document.getElementById('hourHand');
            var minuteHand = document.getElementById('minuteHand');
            var secondHand = document.getElementById('secondHand');
setInterval(function(){
                    var currentTime = new Date();
                    var hourValue = currentTime.getHours();
                    var hourAngle = hourValue / 24 * 360 + 'deg';
                    var minuteValue = currentTime.getMinutes();
                    var minuteAngle = minuteValue / 60 * 360 + 'deg';
                    var secondValue = currentTime.getSeconds();
                    var secondAngle = secondValue / 60 * 360 + 'deg';
                    console.log(hourAngle);
// 方法一:利用jquery的css()增加屬性
var cmdHour = 'rotate('+ hourAngle +')';
$('#hourHand').css({transform:'rotate('+ hourAngle +')'});
var cmdMinute = 'rotate('+ minuteAngle +')';
$('#minuteHand').css({transform:cmdMinute});
var cmdSecond = 'rotate('+ secondAngle +')';
$('#secondHand').css({transform:cmdSecond});

// 方法二:利用DOM元素的style屬性設置
//      hourHand.style.transform = 'rotate('+ hourAngle + ')';
//      minuteHand.style.transform = 'rotate('+ minuteAngle + ')';
//      secondHand.style.transform = 'rotate('+ secondAngle + ')';  

},1000);
}
    </script>
</body>
</html>

總結

以上所述是小編給大家介紹的基于HTML5+CSS3實(shí)現簡(jiǎn)單的時(shí)鐘效果,希望對大家有所幫助,如果大家有任何疑問(wèn)請給我留言,小編會(huì )及時(shí)回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

標簽:通遼 賀州 黃山 懷化 煙臺 湘潭 湖北 山南

巨人網(wǎng)絡(luò )通訊聲明:本文標題《基于HTML5+CSS3實(shí)現簡(jiǎn)單的時(shí)鐘效果》,本文關(guān)鍵詞  ;如發(fā)現本文內容存在版權問(wèn)題,煩請提供相關(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內容系統采集于網(wǎng)絡(luò ),涉及言論、版權與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話(huà)咨詢(xún)

    • 400-1100-266