微信小程序 --- 日历效果

 

这里写图片描述

wxml部分:

<view class='box1' style='width: {{ sysW * 7 }}px'> <view class='dateBox'>{{ year }} - {{ month}}</view> <block wx:for='{{ weekArr }}'> <view style='width: {{ sysW }}px; height: {{ sysW }}px; line-height: {{ sysW }}px;'>{{ item }}</view> </block> <block wx:for='{{ arr }}'> <view style='{{ index == 0 ? "margin-left:" + sysW * marLet + "px;" : "" }}width: {{ sysW }}px; height: {{ sysW }}px; line-height: {{ sysW }}px;' class='{{ item == getDate ? "dateOn" : ""}}'>{{ item }}</view> </block> </view>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

wxss部分:

.box1 .dateBox{
  width: 100%; height: 50px; line-height: 50px; text-align: center; margin-top: 20px; font-size: 40rpx; } .box1{ display: flex; flex-wrap: wrap; margin: 0 auto; } .box1>view{ height: 30px; line-height: 30px; text-align: center; font-size: 34rpx; } .dateOn{ border-radius: 50%; background-color: hotpink; color: #fff; }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

js部分:

// page/index/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    arr: [],
    sysW: null,
    lastDay: null,
    firstDay: null, weekArr: ['日', '一', '二', '三', '四', '五','六'], year: null }, //获取日历相关参数 dataTime: function () { var date = new Date(); var year = date.getFullYear(); var month = date.getMonth() ; var months = date.getMonth() + 1; //获取现今年份 this.data.year = year; //获取现今月份 this.data.month = months; //获取今日日期 this.data.getDate = date.getDate(); //最后一天是几号 var d = new Date(year, months, 0); this.data.lastDay = d.getDate(); //第一天星期几 let firstDay = new Date(year, month, 1); this.data.firstDay = firstDay.getDay(); }, onLoad: function (options) { this.dataTime(); //根据得到今月的最后一天日期遍历 得到所有日期 for (var i = 1; i < this.data.lastDay + 1; i++) { this.data.arr.push(i); } var res = wx.getSystemInfoSync(); this.setData({ sysW: res.windowHeight / 12,//更具屏幕宽度变化自动设置宽度 marLet: this.data.firstDay, arr: this.data.arr, year: this.data.year, getDate: this.data.getDate, month: this.data.month }); } })

转载于:https://www.cnblogs.com/lsongyang/p/10784022.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值