目录
5)调用自定义函数dateTime和setInterval函数,实现动态时钟显示效果
动态时钟显示效果
代码实现
1.创建html文件(时钟显示.html)
2.设置html标签
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>动态时钟显示</title>
</head>
<body>
<div class="div">
<div class="firstDiv"></div>
<div class="lastDiv"></div>
</div>
</body>
</html>
3.设置html标签的CSS样式
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>动态时钟显示</title>
<style>
.div{
/* 宽度400 */
width: 400px;
/*高度400 */
height: 400px;
/* 设置背景色 */
background-color: cornflowerblue;
/* 设置边框圆角200 */
border-radius: 200px;
/* 设置字体粗细700 */
font-weight: 700;
/* 设置文本颜色白色 */
color: white;
/* 设置外边距:上下100px,左右剧中 */
margin: 100px auto;
}
.firstDiv{
/* 设置宽度300 */
width: 300px;
/* 设置高度100 */
height: 100px;
/* 设置行高100 */
line-height: 100px;
/* 设置内容剧中显示 */
text-align: center;
/* 设置字体大小30 */
font-size: 30px;
/* 设置相对定位 */
position: relative;
/* 设置顶端移动100 */
top: 100px;
/* 设置左移动50 */
left: 50px;
}
.lastDiv{
/* 设置宽度300 */
width: 300px;
/* 设置高度100 */
height: 100px;
/* 设置内容剧中显示 */
text-align: center;
/* 设置字体大小30 */
font-size: 30px;
/* 设置相对定位 */
position: relative;
/* 设置顶端移动100 */
top: 100px;
/* 设置左移动50 */
left: 50px;
}
</style>
</head>
<body>
<div class="div">
<div class="firstDiv"></div>
<div class="lastDiv"></div>
</div>
</body>
</html>
4.设置JavaScript
1)创建函数和Date
Date返回的是中国标准时间:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>动态时钟显示</title>
<style>
.div{
/* 宽度400 */
width: 400px;
/*高度400 */
height: 400px;
/* 设置背景色 */
background-color: cornflowerblue;
/* 设置边框圆角200 */
border-radius: 200px;
/* 设置字体粗细700 */
font-weight: 700;
/* 设置文本颜色白色 */
color: white;
/* 设置外边距:上下100px,左右剧中 */
margin: 100px auto;
}
.firstDiv{
/* 设置宽度300 */
width: 300px;
/* 设置高度100 */
height: 100px;
/* 设置行高100 */
line-height: 100px;
/* 设置内容剧中显示 */
text-align: center;
/* 设置字体大小30 */
font-size: 30px;
/* 设置相对定位 */
position: relative;
/* 设置顶端移动100 */
top: 100px;
/* 设置左移动50 */
left: 50px;
}
.lastDiv{
/* 设置宽度300 */
width: 300px;
/* 设置高度100 */
height: 100px;
/* 设置内容剧中显示 */
text-align: center;
/* 设置字体大小30