最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

小程序?qū)崿F(xiàn)橫向滑動(dòng)日歷效果

 更新時(shí)間:2022年08月29日 08:48:23   作者:煥想-不怎么回復(fù)博客  
這篇文章主要介紹了小程序?qū)崿F(xiàn)橫向滑動(dòng)日歷效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了小程序?qū)崿F(xiàn)橫向滑動(dòng)日歷效果的具體代碼,供大家參考,具體內(nèi)容如下

<scroll-view class="scroll-view_H" scroll-x>
 <view class='list' style='width:{{ width }}rpx'>
  <view bindtap="select" wx:for="{{ calendar }}" wx:key="" wx:for-item="item" wx:for-index="index" data-index="{{ index }}" class='listItem {{index==currentIndex? "current":""}}'>
  <text class='name'>{{ item.week }}</text>
  <text class='date'>{{ item.date }}</text>
  </view>
 </view>
</scroll-view>

js: 

function getThisMonthDays(year, month) {
  return new Date(year, month, 0).getDate();
 }
 // 計(jì)算每月第一天是星期幾
 function getFirstDayOfWeek(year, month) {
  return new Date(Date.UTC(year, month - 1, 1)).getDay();
 }
 const date = new Date();
 const cur_year = date.getFullYear();
 const cur_month = date.getMonth() + 1;
 const cur_date = date.getDate();
 const weeks_ch = ['日', '一', '二', '三', '四', '五', '六'];
 //利用構(gòu)造函數(shù)創(chuàng)建對(duì)象
 function calendar(date, week) {
  this.date = cur_year + '-' + cur_month + '-' + date;
  if (date == cur_date) {
  this.week = "今天";
  } else if (date == cur_date + 1) {
  this.week = "明天";
  } else {
  this.week = '星期' + week;
  }
 }
 //當(dāng)前月份的天數(shù)
 var monthLength = getThisMonthDays(cur_year, cur_month)
 //當(dāng)前月份的第一天是星期幾
 var week = getFirstDayOfWeek(cur_year, cur_month)
 var x = week;
 for (var i = 1; i <= monthLength; i++) {
  //當(dāng)循環(huán)完一周后,初始化再次循環(huán)
  if (x > 6) {
  x = 0;
  }
  //利用構(gòu)造函數(shù)創(chuàng)建對(duì)象
  that.data.calendar[i] = new calendar(i, [weeks_ch[x]][0])
  x++;
 }
 //限制要渲染的日歷數(shù)據(jù)天數(shù)為7天以?xún)?nèi)(用戶體驗(yàn))
 var flag = that.data.calendar.splice(cur_date, that.data.calendar.length - cur_date <= 7 ? that.data.calendar.length : 7)
 that.setData({
  calendar: flag
 })
 selectd = flag;
 // console.log(selectd);
 var ret_id = [];
 const lengths = selectd.length
 for (let i = 0; i < lengths; i++) {
  ret_id[i] = selectd[i].date;
 }
 choosedate = ret_id[0];
 //設(shè)置scroll-view的子容器的寬度
 that.setData({
  width: 186 * parseInt(that.data.calendar.length - cur_date <= 7 ? that.data.calendar.length : 7)
 })

CSS:

/*日歷開(kāi)始 */
scroll-view{
 height: 128rpx;
 width: 101%;
 position:fixed;
 top:355rpx;
 
}
scroll-view .list{
 display: flex;
 flex-wrap: nowrap;
 justify-content: flex-start;
}
scroll-view .listItem{
 text-align: center;
 width:187rpx;
 height: 128rpx;
 background: #f4f4f4;
 padding-top: 30rpx;
 box-sizing: border-box;
 display: inline-block;
}
scroll-view .listItem text{
 display: block;
}
scroll-view .listItem .name{
 font-size: 25rpx;
}
scroll-view .listItem .date{
 font-size: 25rpx;
}
scroll-view .current{
 background-color:pink;
  width:200rpx;
 position:relative;
}
scroll-view .current text{
 color: #fff;
}

更多精彩的日歷效果請(qǐng)學(xué)習(xí)參考專(zhuān)題:javascript日歷插件

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

相關(guān)文章

最新評(píng)論

汉寿县| 苍南县| 平顶山市| 嵩明县| 松原市| 盐源县| 高碑店市| 辰溪县| 颍上县| 镇沅| 皋兰县| 蒙城县| 彭阳县| 孝感市| 家居| 彰武县| 如皋市| 临清市| 南涧| 肃宁县| 井陉县| 开封市| 福清市| 临清市| 铁岭市| 平邑县| 平乐县| 辽中县| 万全县| 新昌县| 股票| 灵璧县| 化州市| 平山县| 略阳县| 宕昌县| 上杭县| 景东| 嘉义市| 福清市| 横山县|