DDR爱好者之家 Design By 杰米
本文实例为大家分享了微信小程序日历效果的具体代码,供大家参考,具体内容如下
源码下载地址
项目需要一个日历功能,花了一天时间实现的微信小程序日历,js大小只有几k,引入了bootstrap字体图标(文件icon.wxss,该字体已经bootstrap字体图标需要的字体)看起来有80k,出去icon.wxss整个只有几k,有问题欢迎指正
如图:
index.wxml
<view class="page"> <view class="box"> <view class="box-flex"> <view class="flex-item"> <view class="item-content" bindtap="doDay" data-key='left'> <view class="glyphicon glyphicon-triangle-left"></view> </view> </view> <view class="flex-item item-content-current-day"> <view class="item-content">{{currentDate}}</view> </view> <view class="flex-item"> <view class="item-content" bindtap="doDay" data-key="right"> <view class="glyphicon glyphicon-triangle-right"></view> </view> </view> </view> <view class="box-flex"> <view class="flex-item"> <view class="item-content">一</view> </view> <view class="flex-item"> <view class="item-content">二</view> </view> <view class="flex-item"> <view class="item-content">三</view> </view> <view class="flex-item"> <view class="item-content">四</view> </view> <view class="flex-item"> <view class="item-content">五</view> </view> <view class="flex-item"> <view class="item-content">六</view> </view> <view class="flex-item"> <view class="item-content">日</view> </view> </view> <view class="box-flex"> <view class="flex-item" wx:for="{{currentDayList}}" wx:for-index='key' wx:for-item="vo" wx:key="{{key}}"> <view class="item-content" wx:if="{{currentDay != vo}}">{{vo}}</view> <view class="item-content bk-color-day" wx:else>{{vo}}</view> </view> </view> </view> </view>
index.wxss
@import '../../dist/css/icon.wxss'; page { background-color: #2a8cef; background:-webkit-gradient(linear, 0 0, 0 bottom, from(#2a8cef), to(#8A2BE2)); display: flex; flex-direction: column; width: 100%; height: 100%; flex-wrap: nowrap; justify-content: flex-start; align-items: stretch; font-size: 14px; } .box { display: block; margin: 10px; } .box-flex { display: -webkit-box; display: -webkit-flex; display: flex; flex-wrap: wrap; } .flex-item { flex-flow: nowrap; flex-grow: 1; flex-shrink: 1; width: 14.2%; } .item-content { margin: 5px; padding: 0 10px; text-align: center; background-color: #000; height: 2rem; line-height: 2rem; color: #fff; } .bk-color-day { background-color: #8A2BE2; } .item-content-current-day { flex-grow: 2; }
index.js
var app = getApp(); Page({ data: { currentDate: "2017年05月03日", dayList: '', currentDayList: '', currentObj: '', currentDay: '' }, onLoad: function (options) { var currentObj = this.getCurrentDayString() this.setData({ currentDate: currentObj.getFullYear() + '年' + (currentObj.getMonth() + 1) + '月' + currentObj.getDate() + '日', currentDay: currentObj.getDate(), currentObj: currentObj }) this.setSchedule(currentObj) }, doDay: function (e) { var that = this var currentObj = that.data.currentObj var Y = currentObj.getFullYear(); var m = currentObj.getMonth() + 1; var d = currentObj.getDate(); var str = '' if (e.currentTarget.dataset.key == 'left') { m -= 1 if (m <= 0) { str = (Y - 1) + '/' + 12 + '/' + d } else { str = Y + '/' + m + '/' + d } } else { m += 1 if (m <= 12) { str = Y + '/' + m + '/' + d } else { str = (Y + 1) + '/' + 1 + '/' + d } } currentObj = new Date(str) this.setData({ currentDate: currentObj.getFullYear() + '年' + (currentObj.getMonth() + 1) + '月' + currentObj.getDate() + '日', currentObj: currentObj }) this.setSchedule(currentObj); }, getCurrentDayString: function () { var objDate = this.data.currentObj if (objDate != '') { return objDate } else { var c_obj = new Date() var a = c_obj.getFullYear() + '/' + (c_obj.getMonth() + 1) + '/' + c_obj.getDate() return new Date(a) } }, setSchedule: function (currentObj) { var that = this var m = currentObj.getMonth() + 1 var Y = currentObj.getFullYear() var d = currentObj.getDate(); var dayString = Y + '/' + m + '/' + currentObj.getDate() var currentDayNum = new Date(Y, m, 0).getDate() var currentDayWeek = currentObj.getUTCDay() + 1 var result = currentDayWeek - (d % 7 - 1); var firstKey = result <= 0 ? 7 + result : result; var currentDayList = [] var f = 0 for (var i = 0; i < 42; i++) { let data =[] if (i < firstKey - 1) { currentDayList[i] = '' } else { if (f < currentDayNum) { currentDayList[i] = f + 1 f = currentDayList[i] } else if (f >= currentDayNum) { currentDayList[i] = '' } } } that.setData({ currentDayList: currentDayList }) } })
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米
暂无评论...
更新日志
2024年11月25日
2024年11月25日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]