私は css3ing を学習していて、transformr を学習しています。これを使って小さな時計を作ることを突然思いつきました。 始めましょう:
- 事前作業を準備し、時計の文字盤、時、分、秒を作成します。
<div class="main"> <div id="timeLabel"></div> <div id="hour"></div> <div id="minute"></div> <div id="second"></div> </div>
css コードは次のとおりです:
1 <style> 2 * { 3 margin: 0; 4 padding: 0; 5 } 6 .main { 7 position: relative; 8 margin: 100px auto; 9 width: 300px; 10 height: 300px; 11 border-radius: 300px; 12 border: 1px solid #000; 13 box-shadow:2px 5px; 14 } 15 #timeLabel { 16 position: absolute; 17 background-color:pink; 18 width:100px; 19 height:30px; 20 left:100px; 21 top:180px; 22 } 23 24 #hour { 25 width: 100px; 26 height: 10px; 27 background-color: red; 28 position:absolute; 29 left:150px; 30 top:145px; 31 } 32 #minute { 33 width:120px; 34 height:8px; 35 background-color:blue; 36 position:absolute; 37 left:150px; 38 top:146px; 39 } 40 #second { 41 width: 140px; 42 height: 4px; 43 background-color: green; 44 position: absolute; 45 left: 150px; 46 top: 148px; 47 } 48 </style>
2. デフォルトを初期化します。時間とダイヤルスケールの効果は次のとおりです:
変更されたCSコード:
<style> * { margin: 0; padding: 0; } .main { position: relative; margin: 100px auto; width: 300px; height: 300px; border-radius: 300px; border: 1px solid #000; box-shadow: 2px 5px #808080; } #timeLabel { position: absolute; background-color: pink; width: 80px; height: 25px; left: 110px; top: 180px; color: #fff; line-height: 25px; text-align: center; } #hour { width: 100px; height: 10px; background-color: red; position: absolute; left: 150px; top: 145px; transform-origin: 0 50%; } #minute { width: 120px; height: 8px; background-color: blue; position: absolute; left: 150px; top: 146px; transform-origin: 0 50%; } #second { width: 140px; height: 4px; background-color: green; position: absolute; left: 150px; top: 148px; transform-origin: 0 50%; } .hourPointer, .minuterPointer, .secondPointer { position: absolute; transform-origin: 0 50%; } .hourPointer { height: 10px; width: 12px; left: 150px; top: 145px; background-color: #f00; z-index:3; } .minuterPointer { height: 8px; width: 10px; left: 150px; top: 146px; background-color: #b6ff00; z-index: 2; } .secondPointer { height: 6px; width: 8px; left: 150px; top: 147px; background-color: #fa8; z-index: 1; } </style>
初期化jsコード:
window.onload = function () { initClock(); } var timer = null; function $(id) { return document.getElementById(id) } function CreateKeDu(pElement, className, deg, translateWidth) { var Pointer = document.createElement("div"); Pointer.className = className Pointer.style.transform = "rotate(" + deg + "deg) translate(" + translateWidth + "px)"; pElement.appendChild(Pointer); } function initClock() { var main = $("biaopan"); var timeLabel = $("timeLabel"); var hour = $("hour"); var minute = $("minute"); var second = $("second"); var now = new Date(); var nowHour = now.getHours(); var nowMinute = now.getMinutes(); var nowSecond = now.getSeconds(); //初始化timeLabel timeLabel.innerHTML = nowHour + ":" + nowMinute + ":" + nowSecond; //初始化表盘 for (var index = 0; index < 4; index++) { CreateKeDu(main, "hourPointer", index * 90, 138); } for (var index = 0; index < 12; index++) { CreateKeDu(main, "minuterPointer",index*30, 140); } for (var index = 0; index < 60; index++) { CreateKeDu(main, "secondPointer", index * 6, 142); } //初始化时分秒针 second.style.transform = "rotate(" + (nowSecond * 6 - 90) + "deg)"; minute.style.transform = "rotate(" + (nowMinute * 6 + 1 / 10 * nowSecond - 90) + "deg)"; hour.style.transform = "rotate(" + (nowHour * 30 + 1 / 2 * nowMinute + 1 / 120 * nowSecond - 90) + "deg)"; }
3. タイマーを追加します。
jsコードは次のとおりです以下:
//定时器 function startMove() { clearInterval(timer); timer = setInterval(function () { var now = new Date(); var nowSecond = now.getSeconds(); var nowMinute = now.getMinutes(); var nowHour = now.getHours(); second.style.transform = "rotate(" + (nowSecond * 6 - 90) + "deg)"; minute.style.transform = "rotate(" + (nowMinute * 6 + 1 / 10 * nowSecond - 90) + "deg)"; hour.style.transform = "rotate(" + (nowHour * 30 + 1 / 2 * nowMinute + 1 / 120 * nowSecond - 90) + "deg)"; timeLabel.innerHTML = nowHour + ":" + nowMinute + ":" + nowSecond; }, 1000); }
4. OOPメソッドを使用して変更します:
変更されたjsコードは次のとおりです:
function Clock() { //定义属性 this.main = this.$("biaopan"); this.timeLabel = this.$("timeLabel"); this.hour = this.$("hour"); this.minute = this.$("minute"); this.second = this.$("second"); this.nowHour = null; this.nowMinute = null; this.nowSecond = null; this.timer = null; var _this = this; //初始化函数 var init = function () { _this.getNowTime(); _this.initClock(); _this.InterVal(); } init(); } Clock.prototype.$ = function (id) { return document.getElementById(id) } Clock.prototype.CreateKeDu = function (className, deg, translateWidth) { var Pointer = document.createElement("div"); Pointer.className = className Pointer.style.transform = "rotate(" + deg + "deg) translate(" + translateWidth + "px)"; this.main.appendChild(Pointer); } Clock.prototype.getNowTime = function () { var now = new Date(); this.nowHour = now.getHours(); this.nowMinute = now.getMinutes(); this.nowSecond = now.getSeconds(); } Clock.prototype.setPosition = function () { this.second.style.transform = "rotate(" + (this.nowSecond * 6 - 90) + "deg)"; this.minute.style.transform = "rotate(" + (this.nowMinute * 6 + 1 / 10 * this.nowSecond - 90) + "deg)"; this.hour.style.transform = "rotate(" + (this.nowHour * 30 + 1 / 2 * this.nowMinute + 1 / 120 * this.nowSecond - 90) + "deg)"; } Clock.prototype.initClock = function () { //初始化timeLabel this.timeLabel.innerHTML = this.nowHour + ":" + this.nowMinute + ":" + this.nowSecond; //初始化表盘 for (var index = 0; index < 4; index++) { this.CreateKeDu("hourPointer", index * 90, 138); } for (var index = 0; index < 12; index++) { this.CreateKeDu("minuterPointer", index * 30, 140); } for (var index = 0; index < 60; index++) { this.CreateKeDu("secondPointer", index * 6, 142); } this.setPosition(); } Clock.prototype.InterVal = function () { clearInterval(this.timer); var _this = this; this.timer = setInterval(function () { _this.getNowTime(); _this.second.style.transform = "rotate(" + (_this.nowSecond * 6 - 90) + "deg)"; _this.minute.style.transform = "rotate(" + (_this.nowMinute * 6 + 1 / 10 * _this.nowSecond - 90) + "deg)"; _this.hour.style.transform = "rotate(" + (_this.nowHour * 30 + 1 / 2 * _this.nowMinute + 1 / 120 * _this.nowSecond - 90) + "deg)"; _this.timeLabel.innerHTML = _this.nowHour + ":" + _this.nowMinute + ":" + _this.nowSecond; }, 1000); }
最後の呼び出しは次のとおりです:
れー
最終ページコード:
window.onload = function () { new Clock(); }概要: この例 css3のtransform属性の回転エフェクトとrotateのtranslateをDisplacementエフェクトで使用しています。transformの使い方についてはhttp://wwwを参照してください。 w3school.com.cn/cssref/pr_transform.asp

HTMLは、Webページを構築するために使用される言語であり、タグと属性を使用してWebページの構造とコンテンツを定義します。 1)htmlは、などのタグを介してドキュメント構造を整理します。 2)ブラウザはHTMLを分析してDOMを構築し、Webページをレンダリングします。 3)マルチメディア関数を強化するなど、HTML5の新機能。 4)一般的なエラーには、閉じられていないラベルと引用されていない属性値が含まれます。 5)最適化の提案には、セマンティックタグの使用とファイルサイズの削減が含まれます。

webdevelopmentReliesOnhtml、css、andjavascript:1)htmlStructuresContent、2)cssStylesit、および3)Javascriptaddsinteractivity、形成、

HTMLの役割は、タグと属性を使用してWebページの構造とコンテンツを定義することです。 1。HTMLは、読みやすく理解しやすいようなタグを介してコンテンツを整理します。 2。アクセシビリティとSEOを強化するには、セマンティックタグなどを使用します。 3. HTMLコードの最適化により、Webページの読み込み速度とユーザーエクスペリエンスが向上する可能性があります。

HTML、CSS、およびJavaScriptは、Web開発の3つの柱です。 1。HTMLは、Webページ構造を定義し、などなどのタグを使用します。2。CSSは、色、フォントサイズなどのセレクターと属性を使用してWebページスタイルを制御します。

HTMLはWeb構造を定義し、CSSはスタイルとレイアウトを担当し、JavaScriptは動的な相互作用を提供します。 3人はWeb開発で職務を遂行し、共同でカラフルなWebサイトを構築します。

HTMLは、簡単に学習しやすく、結果をすばやく見ることができるため、初心者に適しています。 1)HTMLの学習曲線はスムーズで簡単に開始できます。 2)基本タグをマスターして、Webページの作成を開始します。 3)柔軟性が高く、CSSおよびJavaScriptと組み合わせて使用できます。 4)豊富な学習リソースと最新のツールは、学習プロセスをサポートしています。

Anexampleapalofastartingtaginhtmlis、それはaperginsaparagraph.startingtagsaresentionentientiontheyinitiateelements、definetheirtypes、およびarecrucialforurturingwebpagesandcontingthomedomを構築します。


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

MantisBT
Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

MinGW - Minimalist GNU for Windows
このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

EditPlus 中国語クラック版
サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境
