本文实例为大家分享了js+css3实现简单时钟的具体代码,供大家参考,具体内容如下
1.实现了时钟的特效,可以转动,时间准确,画面美观大气;
2.用到了css3的transform: rotate,transform-origin:,伪元素,border-radius,定位,z-index等等
效果如图:
代码如下:
CSS3时钟特效 .clock { width: 400px; height: 400px; position: relative; margin: 40px auto; border-radius: 50%; box-shadow: 5px 5px 20px rgba(0, 0, 0, 0.5); background: #F5DEB3; border: 10px solid #FFFF00; } .box { width: 100%; height: 100%; position: absolute; top: 0; left: 0; } .box div { width: 0px; height: 200px; position: absolute; left: 200px; transform: rotate(0deg); transform-origin: bottom right; background: rgba(255, 0, 0, 0.5); } .box div i { float: left; margin-top: 20px; margin-left: -10px; font-style: normal; width: 20px; text-align: center; font-style: 18px; } .box div::after { content: ""; position: absolute; background: #484848; width: 2px; height: 10px; left: -1px; } .box div.five::after { position: absolute; content: ""; width: 4px; height: 20px; left: -2px; top: 0; background: #484848; border-radius: 0 0 2px 2px; } .second { width: 1px; height: 200px; background: red; position: absolute; left: 200px; margin-top: 30px; z-index: 10; transform: rotate(0deg); transform-origin: center 170px; } .second::after { content: ""; position: absolute; width: 20px; height: 20px; background: red; border-radius: 50%; bottom: 20px; left: -10px; } .minute { width: 2px; height: 140px; background: #8b8b8d; position: absolute; left: 199px; margin-top: 60px; z-index: 9; transform-origin: center bottom; transform: rotate(12deg); animation: minute 60s linear infinite; } .hour { width: 6px; height: 100px; background: #333; position: absolute; left: 197px; margin-top: 100px; z-index: 8; border-radius: 3px; transform: rotate(2deg); transform-origin: center bottom; animation: minute 60s linear infinite; }
精简版:
CSS3时钟特效 .clock { width: 400px; height: 400px; position: relative; margin: 40px auto; border-radius: 50%; box-shadow: 5px 5px 20px rgba(0, 0, 0, 0.5); background: #F5DEB3; border: 10px solid #FFFF00; } .box { width: 100%; height: 100%; position: absolute; top: 0; left: 0; } .box div { width: 0px; height: 200px; position: absolute; left: 200px; transform: rotate(0deg); transform-origin: bottom right; background: rgba(255, 0, 0, 0.5); } .box div:after { content: ""; position: absolute; background: #484848; width: 2px; height: 10px; left: -1px; } .box div.five:after { position: absolute; content: ""; width: 4px; height: 20px; left: -2px; top: 0; background: #484848; border-radius: 0 0 2px 2px; } .second { width: 1px; height: 200px; background: red; position: absolute; left: 200px; margin-top: 30px; z-index: 10; transform: rotate(0deg); transform-origin: center 170px; } .second:after { content: ""; position: absolute; width: 20px; height: 20px; background: red; border-radius: 50%; bottom: 20px; left: -10px; } .minute { width: 2px; height: 140px; background: #8b8b8d; position: absolute; left: 199px; margin-top: 60px; z-index: 9; transform-origin: center bottom; transform: rotate(12deg); } .hour { width: 6px; height: 100px; background: #333; position: absolute; left: 197px; margin-top: 100px; z-index: 8; border-radius: 3px; transform: rotate(2deg); transform-origin: center bottom; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。



