欢迎访问我们的博客:http://www.w3ctrain.com/2015/07/06/Apple-Watch-Dials/
随着苹果表的大量生产,我想,用CSS来实现拨号动画的时候到了。
在这篇文章中,我们将使用keyframe动画和一点小技巧来实现苹果标表盘进度条动画。
Demo
这是最终效果如下:
See the Pen Apple Watch Activity Dials CSS by Helkyle (@HelKyle) on CodePen.
拨号进度条
表的动画是由3个线条构成的,每个都是进度条。进度条两边带有圆角。我们将使用一点小技巧来实现。
我们先来画半个圆。HTML代码如下:
<div class="dial-container"> <div class="wedge"></div></div>
我们使用border-radius属性和keyframe来实现半月形状和旋转动画。
(图片为gif)
.wedge { animation: rotate 4s infinite linear; border-radius: 0 4em 4em 0; background: red; width: 2em; height: 4em; transform-origin: 0% 50%; }@keyframes rotate { 100% { transform: rotateZ(360deg); }}遮罩
按照往常的做法,我可能会使用CSS3的clip属性。但是由于浏览器内核兼容性问题,我决定还是放弃。这里,我们简单使用overflow:hidden就够了。
这里使用了两个元素,dial-container的宽度只有wedge的一半,而且它设置了overflow为hidden,容器的位置在半圆的右边,并旋转wedge,这样就出现了扇形效果。
.dial-container { position: absolute; top: 0; left: 2em; width: 2em; height: 4em; overflow: hidden; }
为了画完整个圆,我们需要创建第二个wedge和第二个container,放在左边。
我使用了一个wrapper来给两个containers定位。
<div class="wrapper"> <div class="dial-container container1"> <div class="wedge"></div> </div> <div class="dial-container container2"> <div class="wedge"></div> </div></div>
并使用下面css来处理它们的位置关系。
.wrapper { position: absolute; width: 4em; height: 4em; left: calc(50% - 2em); }.dial-container { position: absolute; top: 0; bottom: 0; overflow: hidden; width: 2em; }.wedge { background: red; height: 4em; width: 2em; }.container1 { left: 2em; }.container1 .wedge { animation: rotate-bg-1 4s infinite linear; border-radius: 0 4em 4em 0; left: 0; transform-origin: 0 50%; }.container2 { left: 0; }.container2 .wedge { animation: rotate-bg-2 4s infinite linear; border-radius: 4em 0 0 4em; transform-origin: 2em 2em; }/* First animation moves 180 degrees in the first 2 seconds */@keyframes rotate-bg-1 { 50%, 100% { transform: rotateZ(180deg); }}/* Second animation moves 180 degrees in the last 2 seconds */@keyframes rotate-bg-2 { 0%, 50% { transform: rotateZ(0); } 100% { transform: rotateZ(180deg); }}
运行结果:
进度
下一步是让wedge变成进度条。我们可以使用伪类在中间画个圆圈遮盖掉。
<div class="wrapper"> <div class="dial-container container1"> <div class="wedge"></div> </div> <div class="dial-container container2"> <div class="wedge"></div> </div></div>
.wrapper::after { content: ""; background: #fff; border-radius: 50%; width: 3em; height: 3em; position: absolute; top: 0.5em; left: 0.5em; }
现在看起来有点进度条的样子了。
边缘处理
苹果表动画看起来很柔和还跟它的圆角有关。要创建这样的圆角,在weget上用css属性时不行的。不过我们可以使用点小技巧。
<div class="wrapper"> <div class="dial-container container1"> <div class="wedge"></div> </div> <div class="dial-container container2"> <div class="wedge"></div> </div> <div class="marker start"></div> <div class="marker end"></div></div>
start元素和end元素是两个多余的元素用来放在进度条的开始和结尾(这样就生成圆角了!)
.marker { background: green; border-radius: 50%; height: 0.5em; width: 0.5em; position: absolute; top: 0; left: calc(50% - 0.25em); }.end { animation: rotate-marker 4s infinite linear; transform-origin: 50% 2em; }@keyframes rotate-marker { 100% { transform: rotateZ(360deg); }}
上面的css把end圆设成绿色。并把transform-origin设置成容器中点。
整合到一起
三个这样的进度条整合到一起,就生成苹果表的动画效果。酷吗?
See the Pen Apple Watch Activity Dials CSS by Helkyle (@HelKyle) on CodePen.

HTML의 역할은 태그 및 속성을 통해 웹 페이지의 구조와 내용을 정의하는 것입니다. 1. HTML은 읽기 쉽고 이해하기 쉽게하는 태그를 통해 컨텐츠를 구성합니다. 2. 접근성 및 SEO와 같은 시맨틱 태그 등을 사용하십시오. 3. HTML 코드를 최적화하면 웹 페이지로드 속도 및 사용자 경험이 향상 될 수 있습니다.

"Code"는 "Code"BroadlyIncludeLugageslikeJavaScriptandPyThonforFunctureS (htMlisAspecificTypeofCodeFocudecturecturingWebContent)

HTML, CSS 및 JavaScript는 웹 개발의 세 가지 기둥입니다. 1. HTML은 웹 페이지 구조를 정의하고 등과 같은 태그를 사용합니다. 2. CSS는 색상, 글꼴 크기 등과 같은 선택기 및 속성을 사용하여 웹 페이지 스타일을 제어합니다.

HTML은 웹 구조를 정의하고 CSS는 스타일과 레이아웃을 담당하며 JavaScript는 동적 상호 작용을 제공합니다. 세 사람은 웹 개발에서 의무를 수행하고 화려한 웹 사이트를 공동으로 구축합니다.

HTML은 간단하고 배우기 쉽고 결과를 빠르게 볼 수 있기 때문에 초보자에게 적합합니다. 1) HTML의 학습 곡선은 매끄럽고 시작하기 쉽습니다. 2) 기본 태그를 마스터하여 웹 페이지를 만들기 시작하십시오. 3) 유연성이 높고 CSS 및 JavaScript와 함께 사용할 수 있습니다. 4) 풍부한 학습 리소스와 현대 도구는 학습 과정을 지원합니다.

anexampleStartingtaginhtmlis, whithbeginsaparagraph.startingtagsareessentialinhtmlastheyinitiate rements, definetheirtypes, andarecrucialforstructurituringwebpages 및 smanstlingthedom.

메뉴에서 점선 분할 효과를 설계하는 방법은 무엇입니까? 메뉴를 설계 할 때는 일반적으로 접시 이름과 가격 사이에 왼쪽과 오른쪽을 정렬하는 것이 어렵지 않지만 점선 또는 중간의 점은 어떻습니까?

웹 코드 편집기의 HTML 요소 분석 많은 온라인 코드 편집기를 사용하면 사용자가 HTML, CSS 및 JavaScript 코드를 입력 할 수 있습니다. 최근에 누군가가 제안했습니다 ...


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

SublimeText3 Linux 새 버전
SublimeText3 Linux 최신 버전

WebStorm Mac 버전
유용한 JavaScript 개발 도구

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기
