当前位置:网站首页>Scroll view specifies the starting position of the scrolling element
Scroll view specifies the starting position of the scrolling element
2022-07-03 06:22:00 【Snow falling Xiaoxuan Han】
scroll-into-view attribute , Value of a child element id, Cannot start with a number , Set which direction to scroll , In which direction to scroll to the element .
Use scenario 1 : View data before the current date ( demand : It is the current date when initializing , Then slide from right to left )
<scroll-view enable-flex scroll-x class="scroll-x" scroll-into-view="{
{scrollIntoView}}" style="height: 120rpx;width: 100%;">
<view id="{
{item.id ? item.id : index}}" wx:for="{
{monthList}}" wx:key="index" class="view_item" style="position: relative;">
<view wx:if="{
{item.month == 1}}" style="position: absolute;top: -55rpx;left:40rpx;font-size: 24rpx;color:#a1a1a1;height: 60rpx;">{
{item.year}}</view>
<view style="background-color: {
{
item.background ? item.background : '#f0f8fa'}};" class="view_item_time" bindtap="clickItem" data-item="{
{index}}">{
{item.month}} month </view>
</view>
</scroll-view>
When data is initialized , To the last item The element sets a id by left, And then set scroll-into-view The value of the property is left that will do
Be careful : You should load the list data before setting scroll-into-view The value of the property
Use scenario 2 :scroll-view Combined calendar component , By default, slide right from the current date , Calendar choose which date ,scroll-view Just slide from which date , The optional date is one month after the current date .
Processing data :
data: {
dateList:[],
timeList:[],
showCalender: false,
date: "",
minDate:'',
maxDate:'',
scrollIntoView:'',
},
// Get the current date
getCurrentDate(index) {
var datetime = new Date();
var year = datetime.getFullYear();
var month = datetime.getMonth() + 1 < 10 ? '0' + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
var date = datetime.getDate() < 10 ? '0' + datetime.getDate() : datetime.getDate();
var time = year + '/' + month + '/' + date
// Gets the current date plus 30 Days after , Limit the calendar to post 30 God
var date1 = new Date();
var date2 = new Date(date1);
// Set a day of the month
date2.setDate(date1.getDate() + 30);
let dateLater = date2.getFullYear() + "/" + (date2.getMonth() + 1) + "/" + date2.getDate()
// Minimum and maximum optional dates in the calendar
this.setData({
minDate:new Date(time).getTime(),maxDate:new Date(dateLater).getTime()})
// Get the current date plus the date after a day
let dateList = [],timeList = [],weekList = []
for(let i = 0;i <= 30;i++) {
dateList[i] = new Date(date1)
// List the required data
dateList[i].setDate(date1.getDate() + i)
// Request the complete date data required by the interface
timeList[i] = dateList[i].getFullYear() + "/" + (dateList[i].getMonth() + 1) + "/" + dateList[i].getDate()
// Get the day of the week
weekList[i] = dateList[i].getDay()
}
dateList = dateList.map(item => {
return item.getDate()
})
weekList = weekList.map(item => {
if(item === 0) {
return ' Sunday '
} else if(item == 1) {
return ' Monday '
} else if(item == 2) {
return ' Tuesday '
} else if(item == 3) {
return ' Wednesday '
} else if(item == 4) {
return' Thursday '
} else if(item == 5) {
return ' Friday '
} else if(item == 6) {
return ' Saturday '
}
})
dateList = dateList.map(item => {
return {
date:item}
})
if(index) {
// Selected the date in the calendar , Set... In the corresponding sliding list id
dateList[index].background = '#00bcd4'
dateList[index].color = '#fff'
dateList[index].id = 'target'
} else {
// No calendar selected , The default setting is to slide the first data in the list id
dateList[0].background = '#00bcd4'
dateList[0].color = '#fff'
dateList[0].id = 'target'
}
dateList.map((item1,index1) => {
weekList.map((item2,index2) => {
if(index1 === index2) {
item1.week = item2
}
})
})
// to scroll-view Set up
this.setData({
dateList,timeList,scrollIntoView:'target'})
},
The calendar
<van-calendar poppable row-height='50' min-date="{
{minDate}}" max-date="{
{maxDate}}" show="{
{ showCalender }}" color='rgba(0, 188, 212, 1)' show-title='{
{false}}' close-on-click-overlay show-confirm bind:confirm="chooseDate" bind:close='closeCalender' />
Slide list
<scroll-view enable-flex scroll-x class="scroll-x" scroll-into-view="{
{scrollIntoView}}">
<view id="{
{item.id ? item.id : index}}" style="background-color: {
{
item.background ? item.background : '#fff'}};color: {
{
item.color ? item.color : '#000'}};" class="date-item" bindtap="clickDate" wx:for="{
{dateList}}" wx:key="index" data-index="{
{index}}">
<view class="item-week">{
{item.week}}</view>
<view class="item-date">{
{item.date}}</view>
</view>
</scroll-view>
Select date
chooseDate(e) {
let timeStamp = new Date(Date.parse(e.detail))
let year = timeStamp.getFullYear()
let month = timeStamp.getMonth() + 1
let day = timeStamp.getDate()
let date = `${
year}/${
month}/${
day}`
this.setData({
date,
showCalender: false
})
this.data.timeList.map((item,index) => {
if(item === date) {
// The date in the selected calendar is equal to the date in the sliding list
// Re render the data in the sliding list every time you select a calendar date
this.getCurrentDate(index)
setTimeout(() => {
this.getCurrentDate(index)},500)
} else {
this.data.dateList[index].id = index
this.data.dateList[index].background = '#fff'
this.data.dateList[index].color = '#000'
}
})
this.setData({
dateList:this.data.dateList})
},
边栏推荐
- In depth analysis of kubernetes controller runtime
- Fluentd facile à utiliser avec le marché des plug - ins rainbond pour une collecte de journaux plus rapide
- SVN分支管理
- PHP用ENV获取文件参数的时候拿到的是字符串
- Mysql database
- Oauth2.0 - explanation of simplified mode, password mode and client mode
- Kubernetes notes (V) configuration management
- 从小数据量分库分表 MySQL 合并迁移数据到 TiDB
- 项目总结--01(接口的增删改查;多线程的使用)
- Luogu problem list: [mathematics 1] basic mathematics problems
猜你喜欢
![[system design] proximity service](/img/4a/2e68536cbe385af1d1a591e674fbf0.png)
[system design] proximity service

In depth analysis of kubernetes controller runtime

Use abp Zero builds a third-party login module (I): Principles

Selenium - 改变窗口大小,不同机型呈现的宽高长度会不一样

Skywalking8.7 source code analysis (II): Custom agent, service loading, witness component version identification, transform workflow

Method of converting GPS coordinates to Baidu map coordinates

ThreadLocal的简单理解

phpstudy设置项目可以由局域网的其他电脑可以访问

数值法求解最优控制问题(一)——梯度法

Kubernetes notes (VII) kuberetes scheduling
随机推荐
Judge whether the date time exceeds 31 days
项目总结--2(Jsoup的基本使用)
Shell conditional statement
Simple understanding of ThreadLocal
Support vector machine for machine learning
2022 CISP-PTE(三)命令执行
Use selenium to climb the annual box office of Yien
Characteristics and isolation level of database
Common interview questions
[set theory] equivalence relation (concept of equivalence relation | examples of equivalence relation | equivalence relation and closure)
Zhiniu stock -- 03
代码管理工具
Scripy learning
第8章、MapReduce 生产经验
Interesting research on mouse pointer interaction
JMeter performance automation test
Click cesium to obtain three-dimensional coordinates (longitude, latitude and elevation)
Une exploration intéressante de l'interaction souris - pointeur
What's the difference between using the Service Worker Cache API and regular browser cache?
Print time Hahahahahaha