欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

小程序?qū)崿F(xiàn)帶年月選取效果的日歷

 更新時(shí)間:2018年06月27日 15:23:27   作者:會(huì)飛的尛海豚  
這篇文章主要為大家詳細(xì)介紹了小程序?qū)崿F(xiàn)帶年月選取效果的日歷,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了小程序日歷展示的具體代碼,供大家參考,具體內(nèi)容如下

根據(jù)前面的日歷,又遇到到個(gè)好玩的日歷需求,分享給大家

 

這是個(gè)帶年月左右選取的日歷展示!并且當(dāng)天的對(duì)應(yīng)日會(huì)被高亮顯示!下面看下實(shí)現(xiàn)代碼!

1.wxml代碼結(jié)構(gòu)

<view class='wrap'> 
  <view> 
    <view class='date-show'> 
      <view class='lt-arrow' bindtap='lastMonth'> 
        <image src='../images/nextMonth.png' mode='aspectFit'></image> 
      </view> 
      {{year}}年{{month}}月 
      <view class='rt-arrow' bindtap='nextMonth'> 
        <image src='../images/nextMonth.png' mode='aspectFit'></image> 
      </view> 
    </view> 
  </view> 
  <view class='header'> 
    <view wx:for='{{date}}' class='{{(index == todayIndex) && isTodayWeek ? "weekMark" : ""}}'>{{item}}<view></view></view> 
  </view> 
  <view class='date-box'> 
    <view wx:for='{{dateArr}}' class='{{isToday == item.isToday ? "nowDay" : ""}}' data-date='{{item.isToday}}'>      
      <view class='date-head'> 
        <view>{{item.dateNum}}</view> 
      </view> 
      <view class='date-weight'>{{item.weight}}</view> 
    </view> 
  </view> 
</view> 

2.wxss代碼結(jié)構(gòu)

.date-show{ 
  position: relative; 
  width: 250rpx; 
  font-family: PingFang-SC-Regular; 
  font-size: 40rpx; 
  color: #282828; 
  text-align: center; 
  margin: 59rpx auto 10rpx; 
} 
.lt-arrow,.rt-arrow{ 
  position: absolute; 
  top: 1rpx; 
  width: 60rpx; 
  height: 60rpx; 
} 
.lt-arrow image,.rt-arrow image{ 
  width: 14rpx; 
  height: 26rpx; 
} 
.lt-arrow{ 
  left: -110rpx; 
  transform: rotate(180deg); 
} 
.rt-arrow{ 
  right: -100rpx; 
} 
.header{ 
  font-size: 0; 
  padding: 0 24rpx; 
} 
.header>view{ 
  display: inline-block; 
  width: 14.285%; 
  color: #333; 
  font-size: 30rpx; 
  text-align: center; 
  border-bottom: 1px solid #D0D0D0; 
  padding: 39rpx 0; 
} 
.weekMark{ 
  position: relative; 
} 
.weekMark view{ 
  position: absolute; 
  bottom: 0; 
  left: 0; 
  width: 100%; 
  border-bottom: 1px solid #22A7F6; 
} 
.date-box{ 
  font-size: 0; 
  padding: 10rpx 0; 
} 
.date-box>view{ 
  position: relative; 
  display: inline-block; 
  width: 14.285%; 
  color: #020202; 
  font-size: 40rpx; 
  text-align: center; 
  vertical-align: middle; 
  margin: 15rpx 0; 
} 
.date-head{ 
  height: 60rpx; 
  line-height: 60rpx; 
  font-size: 26rpx; 
} 
.nowDay .date-head{ 
  width: 60rpx; 
  border-radius: 50%; 
  text-align: center; 
  color: #fff; 
  background-color: #22A7F6; 
  margin: 0 auto; 
} 
.date-weight{ 
  font-size: 22rpx; 
  padding: 15rpx 0; 
} 
.nowDay .date-weight{ 
  color: #22A7F6; 
} 
.one{ 
  position: absolute; 
  bottom: 0; 
  right: 5rpx; 
  width: 20rpx; 
  height: 20rpx; 
  border-radius: 50%; 
  background-color: red; 
} 
.two{ 
  position: absolute; 
  bottom: 30rpx; 
  right: 5rpx; 
  width: 20rpx; 
  height: 20rpx; 
  border-radius: 50%; 
  background-color: blue; 
} 

index.js 

//index.js 
//獲取應(yīng)用實(shí)例 
const app = getApp() 
 
Page({ 
 data: { 
    year: 0, 
    month: 0, 
    date: ['日', '一', '二', '三', '四', '五', '六'], 
    dateArr: [], 
    isToday: 0, 
    isTodayWeek: false, 
    todayIndex: 0 
  }, 
 onLoad: function () { 
    let now = new Date(); 
    let year = now.getFullYear(); 
    let month = now.getMonth() + 1; 
    this.dateInit(); 
    this.setData({ 
      year: year, 
      month: month, 
      isToday: '' + year + month + now.getDate() 
    }) 
 }, 
 dateInit: function(setYear,setMonth){ 
    //全部時(shí)間的月份都是按0~11基準(zhǔn),顯示月份才+1 
    let dateArr = [];            //需要遍歷的日歷數(shù)組數(shù)據(jù) 
    let arrLen = 0;             //dateArr的數(shù)組長(zhǎng)度 
    let now = setYear ? new Date(setYear,setMonth) : new Date(); 
    let year = setYear || now.getFullYear(); 
    let nextYear = 0; 
    let month = setMonth || now.getMonth();         //沒有+1方便后面計(jì)算當(dāng)月總天數(shù) 
    let nextMonth = (month + 1) > 11 ? 1 : (month + 1);    
    let startWeek = new Date( year+','+(month + 1)+','+1).getDay();             //目標(biāo)月1號(hào)對(duì)應(yīng)的星期 
    let dayNums = new Date(year,nextMonth,0).getDate();       //獲取目標(biāo)月有多少天 
    let obj = {};     
    let num = 0; 
     
    if(month + 1 > 11){ 
      nextYear = year + 1; 
      dayNums = new Date(nextYear,nextMonth,0).getDate(); 
    } 
    arrLen = startWeek + dayNums; 
    for(let i = 0; i < arrLen; i++){ 
      if(i >= startWeek){ 
        num = i - startWeek + 1; 
        obj = { 
          isToday: '' + year + (month + 1) + num, 
          dateNum: num, 
          weight: 5 
        } 
      }else{ 
        obj = {}; 
      } 
      dateArr[i] = obj; 
    } 
    this.setData({ 
      dateArr: dateArr 
    }) 
 
    let nowDate = new Date(); 
    let nowYear = nowDate.getFullYear(); 
    let nowMonth = nowDate.getMonth() + 1; 
    let nowWeek = nowDate.getDay(); 
    let getYear = setYear || nowYear; 
    let getMonth = setMonth >= 0 ? (setMonth + 1) : nowMonth; 
 
    if (nowYear == getYear && nowMonth == getMonth){ 
      this.setData({ 
        isTodayWeek: true, 
        todayIndex: nowWeek 
      }) 
    }else{ 
      this.setData({ 
        isTodayWeek: false, 
        todayIndex: -1 
      }) 
    } 
  }, 
  lastMonth: function(){ 
    //全部時(shí)間的月份都是按0~11基準(zhǔn),顯示月份才+1 
    let year = this.data.month - 2 < 0 ? this.data.year - 1 : this.data.year; 
    let month = this.data.month - 2 < 0 ? 11 : this.data.month - 2; 
    this.setData({ 
      year: year, 
      month: (month + 1) 
    }) 
    this.dateInit(year,month); 
  }, 
  nextMonth: function(){ 
    //全部時(shí)間的月份都是按0~11基準(zhǔn),顯示月份才+1 
    let year = this.data.month > 11 ? this.data.year + 1 : this.data.year; 
    let month = this.data.month > 11 ? 0 : this.data.month; 
    this.setData({ 
      year: year, 
      month: (month + 1) 
    }) 
    this.dateInit(year, month); 
  } 
}) 

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 測(cè)試JavaScript字符串處理性能的代碼

    測(cè)試JavaScript字符串處理性能的代碼

    主要是測(cè)試了數(shù)組 push()方法與直接相加這兩種在JS引擎上性能的實(shí)際處理情況。程序代碼簡(jiǎn)單明了,沒什么好解釋的。
    2009-12-12
  • 利用原生JS自動(dòng)生成文章標(biāo)題樹的實(shí)例

    利用原生JS自動(dòng)生成文章標(biāo)題樹的實(shí)例

    網(wǎng)上關(guān)于生成文章標(biāo)題樹的示例很多,這篇文章介紹的是利用原生JS實(shí)現(xiàn)自動(dòng)生成文章標(biāo)題樹,實(shí)現(xiàn)過程很簡(jiǎn)單,有需要的可以參考借鑒。
    2016-08-08
  • 微信小程序基礎(chǔ)教程之echart的使用

    微信小程序基礎(chǔ)教程之echart的使用

    簡(jiǎn)單的使用echarts不難,但是在小程序里用echarts可能有些理不清。所以這篇文章主要給大家介紹了關(guān)于微信小程序基礎(chǔ)教程之echart使用的相關(guān)資料,需要的朋友可以參考下
    2021-06-06
  • js和jquery如何獲取圖片真實(shí)的寬度和高度

    js和jquery如何獲取圖片真實(shí)的寬度和高度

    按照插入的圖片的尺寸來(lái)判斷圖片是橫圖還是豎圖。然后判斷過后給予不同的展示方式,下面為大家介紹下js和jquery如何獲取圖片真實(shí)的寬度和高度
    2014-09-09
  • 史上最全JavaScript常用的簡(jiǎn)寫技巧(推薦)

    史上最全JavaScript常用的簡(jiǎn)寫技巧(推薦)

    這篇文章主要介紹了JavaScript常用的簡(jiǎn)寫技巧,列舉了20條js中常用的簡(jiǎn)寫技巧,具體操作步驟大家可查看下文的詳細(xì)講解,感興趣的小伙伴們可以參考一下
    2017-08-08
  • 微信小程序?qū)崿F(xiàn)蒙版彈窗效果

    微信小程序?qū)崿F(xiàn)蒙版彈窗效果

    這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)蒙版彈窗效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-11-11
  • JS瀑布流實(shí)現(xiàn)方法實(shí)例分析

    JS瀑布流實(shí)現(xiàn)方法實(shí)例分析

    這篇文章主要介紹了JS瀑布流實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了javascript瀑布流加載圖片效果的實(shí)現(xiàn)原理、步驟與相關(guān)操作技巧,需要的朋友可以參考下
    2016-12-12
  • 詳解tween.js的使用教程

    詳解tween.js的使用教程

    本篇文章主要介紹了詳解tween.js的使用方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧
    2017-09-09
  • ES7之Async/await的使用詳解

    ES7之Async/await的使用詳解

    這篇文章主要介紹了ES7之Async/await的使用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • javascript使用call調(diào)用微信API

    javascript使用call調(diào)用微信API

    這篇文章主要介紹了javascript使用call調(diào)用微信API,需要的朋友可以參考下
    2014-12-12

最新評(píng)論