小程序?qū)崿F(xiàn)橫向滑動日歷效果
本文實例為大家分享了小程序?qū)崿F(xiàn)橫向滑動日歷效果的具體代碼,供大家參考,具體內(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();
}
// 計算每月第一天是星期幾
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)建對象
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)建對象
that.data.calendar[i] = new calendar(i, [weeks_ch[x]][0])
x++;
}
//限制要渲染的日歷數(shù)據(jù)天數(shù)為7天以內(nèi)(用戶體驗)
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:
/*日歷開始 */
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;
}更多精彩的日歷效果請學(xué)習(xí)參考專題:javascript日歷插件
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
使用BootStrap建立響應(yīng)式網(wǎng)頁——通欄輪播圖(carousel)
這篇文章主要介紹了使用BootStrap建立響應(yīng)式網(wǎng)頁通欄輪播圖(carousel)的相關(guān)資料,需要的朋友可以參考下2016-12-12
WebRTC媒體權(quán)限申請getUserMedia實例詳解
這篇文章主要為大家介紹了WebRTC媒體權(quán)限申請getUserMedia實例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-11-11
利用AJAX實現(xiàn)WordPress中的文章列表及評論的分頁功能
在文中列表頁方面利用AJAX制作滾動到底觸發(fā)翻頁的效果比較常見,而在評論加載時AJAX顯示正在加載也很常用,下面就來看一下如何利用AJAX實現(xiàn)WordPress中的文章列表及評論的分頁功能2016-05-05
利用js實現(xiàn)Vue2.0中數(shù)據(jù)的雙向綁定功能
vue數(shù)據(jù)雙向綁定是通過數(shù)據(jù)劫持結(jié)合發(fā)布者-訂閱者模式的方式來實現(xiàn)的,下面這篇文章主要給大家介紹了關(guān)于如何利用js實現(xiàn)Vue2.0中數(shù)據(jù)的雙向綁定功能的相關(guān)資料,需要的朋友可以參考下2021-07-07
Javascript insertAfter() 實現(xiàn)函數(shù)代碼
DOM沒有提供insertAfter()方法,我們可以自己擴展下。2011-10-10
js中Math之random,round,ceil,floor的用法總結(jié)
本篇文章是對js中Math之random,round,ceil,floor的用法進行了總結(jié)介紹,需要的朋友可以過來參考下,希望對大家有所幫助2013-12-12

