程序员用css3实现网页电子时钟,校准北京时间
2017-11-09 16:49
549 查看
效果知识点:CSS3+JS完美配合,基本语法,编程逻辑,Date对象,获取时分秒钟方法,for循环,CSS3选择器,setInterval定时器。
电子时钟源码:
<!doctype html>
<html lang="en">
<head>
<!--声明当前页面的编码格式 国际编码 UTF-8 中文编码 GBK-->
<meta charset="UTF-8">
<!--声明当前页面的三要素-->
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>css3实现网页电子时钟</title>
<!--样式css 修饰 衣服 化妆品-->
<styletype="text/css">
*{ margin:0;padding:0;}
ul,li{ list-style:none;}
body{ background:radial-gradient(#eeefef,#d6d7d9); padding:50px; }
.box{ width:540px; height:200px; margin:50px auto; }
.box ul li{ width:150px; height:160px; border:1px solid #9fa2ad; display:inline-block; margin-right:10px; text-align: center; border-radius: 5px; box-shadow:inset 0 -2px 0#f1f1f1,0 1px 0 #f1f1f1,02px 0 #9fa2ad,0 3px0 #f1f1f1,04px 0 #9fa2ad; background: -webkit-linear-gradient(top, rgba(248,248,248,.3)20%, rgba(168,173,190,.5)50%, rgba(168,173,190,.3)51%, rgba(248,248,248,.2)90%); position:relative;}
.box li span:first-child{ font-size:120px; color: #52555a; display: block; height: 130px; line-height: 150px;}
.box li:before,
.box li:after{
display: block;
content: "";
position: absolute;
width: 150px;
}
.box li:before{
top:50%;
height: 1px;
box-shadow: 0 1px 0#868995,0 2px 1px #fff;
}
.box li:after{
bottom: -65px;
height: 60px;
border-radius:00 5px 5px;
background: -webkit-gradient(linear,00,0 100%,from(rgba(0,0,0,.1)),to(rgba(0,0,0,0)));
background: -webkit-linear-gradient(top,rgba(0,0,0,.1),rgba(0,0,0,0));
background: linear-gradient(top,rgba(0,0,0,.1),rgba(0,0,0,0));
z-index: 1;
}
</style>
</head>
<body>
<div id="snowzone" >
</div>
<divclass="box">
<ul>
<li><spanid="hour"></span><span>时</span></li>
<li><spanid="minute"></span><span>分</span></li>
<li><spanid="second"></span><span>秒</span></li>
</ul>
</div>
</body>
<scripttype="text/javascript">
var hour =document.getElementById('hour');
var minute =document.getElementById('minute');
var second =document.getElementById('second');
function showTime(){
var oDate =new Date();
var iHours=oDate.getHours();
var iMinute=oDate.getMinutes();
var iSecond=oDate.getSeconds();
hour.innerHTML =AddZero(iHours);
minute.innerHTML =AddZero(iMinute);
second.innerHTML =AddZero(iSecond);
}
showTime();
setInterval(showTime,1000);
function AddZero(n){
if(n <10){
return '0'+n;
}
return ''+n;
}
</script>
</html>
web前端学习群:575308719,分享源码、视频、企业级案例、最新知识点,欢迎初学者和在进阶中的小伙伴。
关注公众号→‘学习web前端’跟大佬一起学前端!
电子时钟源码:
<!doctype html>
<html lang="en">
<head>
<!--声明当前页面的编码格式 国际编码 UTF-8 中文编码 GBK-->
<meta charset="UTF-8">
<!--声明当前页面的三要素-->
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>css3实现网页电子时钟</title>
<!--样式css 修饰 衣服 化妆品-->
<styletype="text/css">
*{ margin:0;padding:0;}
ul,li{ list-style:none;}
body{ background:radial-gradient(#eeefef,#d6d7d9); padding:50px; }
.box{ width:540px; height:200px; margin:50px auto; }
.box ul li{ width:150px; height:160px; border:1px solid #9fa2ad; display:inline-block; margin-right:10px; text-align: center; border-radius: 5px; box-shadow:inset 0 -2px 0#f1f1f1,0 1px 0 #f1f1f1,02px 0 #9fa2ad,0 3px0 #f1f1f1,04px 0 #9fa2ad; background: -webkit-linear-gradient(top, rgba(248,248,248,.3)20%, rgba(168,173,190,.5)50%, rgba(168,173,190,.3)51%, rgba(248,248,248,.2)90%); position:relative;}
.box li span:first-child{ font-size:120px; color: #52555a; display: block; height: 130px; line-height: 150px;}
.box li:before,
.box li:after{
display: block;
content: "";
position: absolute;
width: 150px;
}
.box li:before{
top:50%;
height: 1px;
box-shadow: 0 1px 0#868995,0 2px 1px #fff;
}
.box li:after{
bottom: -65px;
height: 60px;
border-radius:00 5px 5px;
background: -webkit-gradient(linear,00,0 100%,from(rgba(0,0,0,.1)),to(rgba(0,0,0,0)));
background: -webkit-linear-gradient(top,rgba(0,0,0,.1),rgba(0,0,0,0));
background: linear-gradient(top,rgba(0,0,0,.1),rgba(0,0,0,0));
z-index: 1;
}
</style>
</head>
<body>
<div id="snowzone" >
</div>
<divclass="box">
<ul>
<li><spanid="hour"></span><span>时</span></li>
<li><spanid="minute"></span><span>分</span></li>
<li><spanid="second"></span><span>秒</span></li>
</ul>
</div>
</body>
<scripttype="text/javascript">
var hour =document.getElementById('hour');
var minute =document.getElementById('minute');
var second =document.getElementById('second');
function showTime(){
var oDate =new Date();
var iHours=oDate.getHours();
var iMinute=oDate.getMinutes();
var iSecond=oDate.getSeconds();
hour.innerHTML =AddZero(iHours);
minute.innerHTML =AddZero(iMinute);
second.innerHTML =AddZero(iSecond);
}
showTime();
setInterval(showTime,1000);
function AddZero(n){
if(n <10){
return '0'+n;
}
return ''+n;
}
</script>
</html>
web前端学习群:575308719,分享源码、视频、企业级案例、最新知识点,欢迎初学者和在进阶中的小伙伴。
关注公众号→‘学习web前端’跟大佬一起学前端!
相关文章推荐
- [原创]利用php和javascript实现服务器时间电子时钟
- HTML5 CSS3 诱人的实例 : 网页加载进度条的实现,下载进度条等
- JS获取北京时间并制作时钟效果
- js面试题:网页中实现一个计算还剩多少时间的倒数计时程序
- 使用CSS3 Media Queries实现网页自适应(转)
- 网页设计:使用 CSS3 Box Shadow 实现的 10 个创新技术
- js实现在网页上简单显示时间的方法
- CSS3实现鼠标移动到图片上图片变大(缓慢变大,有过渡效果,放大的过程是有动画过渡的,这个过渡的时间可以自定义)
- 时间管理——高精度时钟、动态时钟——实现
- jQuery CSS3相结合实现时钟插件
- jQuery实现的电子时钟效果完整示例
- CSS3实现手机网页3D切换效果
- javascript时间和日期,实现时钟功能
- 网页中实现一个计算当年还剩多少时间的倒数计时程序,要求网页上实时动态显示“××年还剩××天××时××分××秒”
- java实现一个简单的电子时间
- 实现数码电子时间---通过数组来实现对图片的调用
- 使用CSS3的@media来实现网页自适应
- css3实现网页平滑过渡中注意事项
- 网页显示服务器时间和javscript自运行时钟
- 一个早上做的电子时钟(不带调试时间)