当前位置:首页>网站建设>b2教程-网站侧边栏小工具添加彩色时间进度

b2教程-网站侧边栏小工具添加彩色时间进度

释放双眼,带上耳机,听听看~!

时间是动态的哦,代码安装完成后需要清除缓存。如果还是不显示请等待一天即可

代码放到小工具

<div class="html-widget">
				<div class="html-widget-content">
					<div class="sidebar-box classListBox">
<div class="aside aside-count">
<div class="p-3"><span style="font-size: 1.2em; color: orange;"><i class="fas fa-hourglass-half"></i></span> 人生倒计时</div>
<div class="content">
<div class="item" id="dayProgress">
<div class="title">今日已经过去<span></span>小时</div>
<div class="progress">
<div class="progress-bar">
<div class="progress-inner progress-inner-1"></div>
</div>
<div class="progress-percentage"></div>
</div>
</div>
<div class="item" id="weekProgress">
<div class="title">这周已经过去<span></span>天</div>
<div class="progress">
<div class="progress-bar">
<div class="progress-inner progress-inner-2"></div>
</div>
<div class="progress-percentage"></div>
</div>
</div>
<div class="item" id="monthProgress">
<div class="title">本月已经过去<span></span>天</div>
<div class="progress">
<div class="progress-bar">
<div class="progress-inner progress-inner-3"></div>
</div>
<div class="progress-percentage"></div>
</div>
</div>
<div class="item" id="yearProgress">
<div class="title">今年已经过去<span></span>个月</div>
<div class="progress">
<div class="progress-bar">
<div class="progress-inner progress-inner-4"></div>
</div>
<div class="progress-percentage"></div>
</div>
</div>
</div>
</div>
</div>
				</div>
			</div>

以下代码放到child.js

欢迎访问秀主题博客,分享简单实用WP教程
function init_life_time() {
function getAsideLifeTime() {
/* 当前时间戳 */
let nowDate = +new Date();
/* 今天开始时间戳 */
let todayStartDate = new Date(new Date().toLocaleDateString()).getTime();
/* 今天已经过去的时间 */
let todayPassHours = (nowDate - todayStartDate) / 1000 / 60 / 60;
/* 今天已经过去的时间比 */
let todayPassHoursPercent = (todayPassHours / 24) * 100;
$('#dayProgress .title span').html(parseInt(todayPassHours));
$('#dayProgress .progress .progress-inner').css('width', parseInt(todayPassHoursPercent) + '%');
$('#dayProgress .progress .progress-percentage').html(parseInt(todayPassHoursPercent) + '%');
/* 当前周几 */
let weeks = {
0: 7,
1: 1,
2: 2,
3: 3,
4: 4,
5: 5,
6: 6
};
let weekDay = weeks[new Date().getDay()];
let weekDayPassPercent = (weekDay / 7) * 100;
$('#weekProgress .title span').html(weekDay);
$('#weekProgress .progress .progress-inner').css('width', parseInt(weekDayPassPercent) + '%');
$('#weekProgress .progress .progress-percentage').html(parseInt(weekDayPassPercent) + '%');
let year = new Date().getFullYear();
let date = new Date().getDate();
let month = new Date().getMonth() + 1;
let monthAll = new Date(year, month, 0).getDate();
let monthPassPercent = (date / monthAll) * 100;
$('#monthProgress .title span').html(date);
$('#monthProgress .progress .progress-inner').css('width', parseInt(monthPassPercent) + '%');
$('#monthProgress .progress .progress-percentage').html(parseInt(monthPassPercent) + '%');
let yearPass = (month / 12) * 100;
$('#yearProgress .title span').html(month);
$('#yearProgress .progress .progress-inner').css('width', parseInt(yearPass) + '%');
$('#yearProgress .progress .progress-percentage').html(parseInt(yearPass) + '%');
}
getAsideLifeTime();
setInterval(() => {
getAsideLifeTime();
}, 1000);
}
init_life_time()

css样式

.aside-count .content {
	padding: 15px
}
.aside-count .content .item {
	margin-bottom: 15px
}
.aside-count .content .item:last-child {
	margin-bottom: 0
}
.aside-count .content .item .title {
	font-size: 12px;
	color: var(--minor);
	margin-bottom: 5px;
	display: flex;
	align-items: center
}
.aside-count .content .item .title span {
	color: var(--theme);
	font-weight: 500;
	font-size: 14px;
	margin: 0 5px
}
.aside-count .content .item .progress {
	display: flex;
	align-items: center
}
.aside-count .content .item .progress .progress-bar {
	height: 10px;
	border-radius: 5px;
	overflow: hidden;
	background: var(--classC);
	width: 0;
	min-width: 0;
	flex: 1;
	margin-right: 5px
}
@keyframes progress {
	0% {
		background-position: 0 0
	}
	100% {
		background-position: 30px 0
	}
}
.aside-count .content .item .progress .progress-bar .progress-inner {
	width: 0;
	height: 100%;
	border-radius: 5px;
	transition: width 0.35s;
	-webkit-animation: progress 750ms linear infinite;
	animation: progress 750ms linear infinite
}
.aside-count .content .item .progress .progress-bar .progress-inner-1 {
	background: #bde6ff;
	background-image: linear-gradient(135deg, #50bfff 25%, transparent 25%, transparent 50%, #50bfff 50%, #50bfff 75%, transparent 75%, transparent 100%);
	background-size: 30px 30px
}
.aside-count .content .item .progress .progress-bar .progress-inner-2 {
	background: #ffd980;
	background-image: linear-gradient(135deg, #f7ba2a 25%, transparent 25%, transparent 50%, #f7ba2a 50%, #f7ba2a 75%, transparent 75%, transparent 100%);
	background-size: 30px 30px
}
.aside-count .content .item .progress .progress-bar .progress-inner-3 {
	background: #ffa9a9;
	background-image: linear-gradient(135deg, #ff4949 25%, transparent 25%, transparent 50%, #ff4949 50%, #ff4949 75%, transparent 75%, transparent 100%);
	background-size: 30px 30px
}
.aside-count .content .item .progress .progress-bar .progress-inner-4 {
	background: #67c23a;
	background-image: linear-gradient(135deg, #4f9e28 25%, transparent 25%, transparent 50%, #4f9e28 50%, #4f9e28 75%, transparent 75%, transparent 100%);
	background-size: 30px 30px
}
.aside-count .content .item .progress .progress-percentage {
	color: var(--info)
}
@-webkit-keyframes background {
	from {
		background-position: 0 0%
	}
	to {
		background-position: 0 -300px
	}
}
@keyframes background {
	from {
		background-position: 0 0%
	}
	to {
		background-position: 0 -300px
	}
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
网站建设

b2教程-网站标题栏添加搞怪词

2023-1-26 15:21:04

网站建设

WordPress网站绑定多个域名,实现多域名不跳转访问访问同一WordPress网站

2023-2-2 12:36:05

温馨提示:

1.本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:971318156@qq.com,我们将第一时间处理!

2.资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。

3.所有资源仅限于参考和学习,版权归原作者所有,更多请阅读网站声明

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索