uniapp 「小程序」考勤系统的日历组件

由于是用uniapp写的,所以在网页上也可以用,先上预览图
日历.gif

主要功能:

  • 点击选中样式
  • 滑动跳转月份
  • 点击非本月日期跳转相应月份

一、css部分

css样式原理如下,红色框为用户视图。拖拉的时候改变left数值就可以了。

视图.png

小tips:
当宽度为自适应,不知道具体数值,而需要用宽度计算时,可以用padding-bottom。这样我们就可以一行放下七个圆形了。

.day-item{
   
			width: 14%;
			display: block;
			border-radius: 50%;
			padding-bottom: 100%;
			height: 0;
		}

所有css如下:
数字偏上是预留位置给当天的状态显示。

<style lang="scss">
.calendar{
     
		width: 92%;
		margin: 15px auto;
		background-color: #fff;
		border-radius:16px;
		padding: 30rpx 20rpx;
		overflow: hidden;

        .threeMonth{
     
			display: flex;
			width: 300%;
			position: relative;
		}
		
		.title{
     
			font-size: 35rpx;
			font-weight: bold;
			padding-bottom: 30rpx;
		}
		
		.day{
     
			display: flex;
			position: relative;
			width: 100%;
			justify-content: space-around;
			flex-wrap: wrap;
			text-align: center;
			align-content: flex-start;
			
			.active{
     
				background-color: #1972F0;
				color: #fff;
			}
		}

		
		.day-item{
     
			width: 14%;
			text{
     
				display: block;
				border-radius: 50%;
				width: 100%;
				padding-top: calc(50% - 1em);
				padding-bottom: calc(50% + 1em);
				height: 0;
			}
		}

}
</style>

二、template部分

<view class="calendar">
	<view class="day">
	  <view class="day-item" v-for="(item,index) in ['日','一','二','三','四','五','六']">
	      {
  {item}}
	  </view>
	</view>

	<!-- 日期 -->
	<view 
		class="threeMonth"    
		@touchstart='touchstart
评论 19
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值