cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div class="clock-bg">
  <span id="wu"></span>
  <div class="clock">
      <div class="hours-con"> 
        <div class="hours"></div>
      </div>
       <div class="minutes-con">
        <div class="minutes"></div>
      </div>
      <div class="seconds-con">
        <div class="seconds"></div>
      </div>
  </div>
  <span class="address">上海</span>
</div>
            
          
!
            
              body {
  font: 12px/1.2 "Microsfot YaHei";
  color: #333;
  background: #151513;
  width: 100vw;
  height: 100vh;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.clock-bg {
  width: 150px;
  height: 150px;
  border-radius: 10px;
  background-image: linear-gradient(
    to bottom,
    #484848 0%,
    #393939 25%,
    #494949 50%,
    #494949 50%,
    #040404 50%,
    #0d0d0d 75%,
    #11110f 100%
  );
  border: 2px solid #010101;
  display: flex;
  display:-webkit-flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
.clock {
  width: 100px;
  height: 100px;
  background: #fff
    url(https://cssanimation.rocks/images/posts/clocks/ios_clock.svg)
    no-repeat
    center
    center;
  margin: 6px 0;
  position: relative;
  border-radius: 50%;
  background-size: 80%;
  box-shadow: 0 0 2px rgba(67, 67, 67, 0.3);
}
.address {
  color: #fff;
  text-shadow: 0 0 1px rgba(0, 0, 0, 0.2);
}
#wu {
  color: #101010;
  text-shadow: 0 0 1px rgba(255, 255, 255, 0.2);
}

.clock::after {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 10;
  transform: translate(-50%, -50%);
  -webkit-transform: translate(-50%, -50%);
  -moz-transform: translate(-50%, -50%);
  -o-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  background: #e43c39;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px #454449;
  content: "";
  display: block;
}
.hours-con, .minutes-con, .seconds-con {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
}
/*时针*/
.hours {
  position: absolute;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 30px solid #000;
  top: 22%;
  left: 50%;
  margin-left: -4px;
  transform-origin: 50% 100%;
  -webkit-transform-origin: 50% 100%;
  -moz-transform-origin: 50% 100%;
  -ms-transform-origin: 50% 100%;
  -o-transform-origin: 50% 100%;
}
/*分针*/
.minutes {
  position: absolute;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 40px solid #000;
  top: 10%;
  left: 50%;
  margin-left: -4px;
  transform-origin: 50% 100%;
  -webkit-transform-origin: 50% 100%;
  -moz-transform-origin: 50% 100%;
  -ms-transform-origin: 50% 100%;
  -o-transform-origin: 50% 100%;
}
.seconds-con {
  z-index: 12;
}
.seconds {
  position: absolute;
  width: 2px;
  height: 48%;
  top: 2%;
  left: 50%;
  background: #e43c39;
  transform-origin: 50% 100%;
  -webkit-transform-origin: 50% 100%;
  -moz-transform-origin: 50% 100%;
  -ms-transform-origin: 50% 100%;
  -o-transform-origin: 50% 100%;
}

.hours-con {
  animation: rotate 43200s infinite linear;
  -webkit-animation: rotate 43200s infinite linear;
  -moz--animation: rotate 43200s infinite linear;
  -ms-animation: rotate 43200s infinite linear;
  -o-animation: rotate 43200s infinite linear;
}
/* .minutes-con{
  animation: rotate 3600s infinite steps(60);
}
.seconds-con{
    animation: rotate 60s infinite steps(60);
} */ /*完全用css实现时钟转动,但是会有分针和秒针的误差*/
.minutes-con {
  transition: transform 0.3s cubic-bezier(.4, 2.08, .55, .44);
  -webkit-transition: transform 0.3s cubic-bezier(.4, 2.08, .55, .44);
  -moz-transition: transform 0.3s cubic-bezier(.4, 2.08, .55, .44);
  -o-transition: transform 0.3s cubic-bezier(.4, 2.08, .55, .44);
  -ms-transition: transform 0.3s cubic-bezier(.4, 2.08, .55, .44);
}
.seconds-con {
  transition: transform 0.2s cubic-bezier(.4, 2.08, .55, .44);
  -webkit-transition: transform 0.2s cubic-bezier(.4, 2.08, .55, .44);
  -moz-transition: transform 0.2s cubic-bezier(.4, 2.08, .55, .44);
  -ms-transition: transform 0.2s cubic-bezier(.4, 2.08, .55, .44);
  -o-transition: transform 0.2s cubic-bezier(.4, 2.08, .55, .44);
}

@keyframes rotate {
  to {
    transform: rotate(360deg);
    -webkit-transform: rotate(360deg);
    -moz-transform: rotate(360deg);
    -ms-transform: rotate(360deg);
    -o-transform: rotate(360deg);
  }
}

            
          
!
            
              window.onload=function(){
	init();
	function init(){
		initLocalClocks();
		setUpMinuteHands();
		moveSecondHands();
	}


	//初始化表盘刻度
	function initLocalClocks() {
		var date=new Date; 
		var hour=date.getHours();
		var min=date.getMinutes();
		var sec=date.getSeconds();
    
    var wu=document.getElementById("wu");
    if(hour>=12){
        wu.innerText="下午";
    }else{
        wu.innerText="上午";
    }

		//为了能测试秒针每跳到12刻度时分针的转动
		// var hour=1;
		// var min=4;
		// var sec=3; 

		// var hourHand=document.querySelector(".hours");
		// var minHand=document.querySelector(".minutes");
		// var secHand=document.querySelector(".seconds");
 
	 	
	 	// hourHand.style.transform='rotate(+'+hour*30+min/2+'deg)';
	 	// minHand.style.transform='rotate(+'+min*6+'deg)';
	 	// secHand.style.transform='rotate(+'+sec*6+'deg)';


	 	var hands=[
	 	{
	 		hand:'hours',
	 		angle:hour*30+min/2
	 	},
	 	{
	 		hand:'minutes',
	 		angle:min*6
	 	},
	 	{
	 		hand:'seconds',
	 		angle:sec*6
	 	}
	 	]

	 	

	 	for(var i=0;i<hands.length;i++){ 
	 		var elements=document.querySelectorAll("."+hands[i].hand);  

	 		for(var j=0;j<elements.length;j++){
	 			elements[j].style.transform='rotate(+'+hands[i].angle+'deg)';
	 			elements[j].style.WebkitTransform='rotate('+hands[i].angle+'deg)'; 


	 			//获取秒针初始时候的位置,以便下面操作秒针到达12刻度时候,分针才转动
	 			if (hands[i].hand === 'minutes') {
					elements[j].parentNode.setAttribute('data-second-angle', hands[i + 1].angle); 
				}    
	 		}
	 	} 
 
	}
	

	//设置秒针和分针转动,无需设置时针的转动,css已解决
	
	function moveSecondHands(){
		var secCons=document.querySelectorAll(".seconds-con"); 
		setInterval(function(){
			for(var i=0;i<secCons.length;i++){
				if(secCons[i].angle===undefined){
					secCons[i].angle=6;
				}else{
					secCons[i].angle+=6;
				}
				secCons[i].style.transform="rotate("+secCons[i].angle+"deg)";
				secCons[i].style.webkitTransform="rotate("+secCons[i].angle+"deg)";
			} 
		},1000)
	}

	function moveMinuteHands(containers){  
		//先把分针转到延迟后的正时刻
		for(var i=0;i<containers.length;i++){
			containers[i].style.webkitTransform = 'rotateZ(6deg)';
    		containers[i].style.transform = 'rotateZ(6deg)';
		}
		//分针进行正常的转动
		setInterval(function(){
			for(var i=0;i<containers.length;i++){
				if(containers[i].angle===undefined){
					containers[i].angle=12;  //注意是在上一个刻度之前,即从4转到6
				}else{
					containers[i].angle+=6;
				}
				containers[i].style.transform="rotate("+containers[i].angle+"deg)";
				containers[i].style.webkitTransform="rotate("+containers[i].angle+"deg)";
			} 
		},60000)
	}


	function setUpMinuteHands(){
		var minCons=document.querySelectorAll(".minutes-con"); 
		var angle=minCons[0].getAttribute('data-second-angle');
		var delay=(360-angle)/6*1000;
		if(angle>0){
			setTimeout(function(){
				 moveMinuteHands(minCons);
			},delay)
		}  
	}

}
            
          
!
999px
Loading ..................

Console