In the applet, you can use onPageScroll() to monitor page scrolling
However, it should be noted that if you check the data while listening while scrolling, it will cause a large amount of data loading
So, take a timer, the time can be adjusted
//监听页面滚动onPageScroll(e){
let sTop = e.scrollTop.toFixed(0);// 屏幕滑动距离let that =thisclearTimeout(that.timer)
that.timer =setTimeout(()=>{
//that.$refs.duiduipeng.changeCell(sTop)//当你操作的数据是子组件的数据的时候采用这个
that.getRectInfo()//如果不是就直接采用页面数据},500)},
Here comes the point!
This practice is in uniapp, first add dynamic id name to html
You need to come up to get all the dom node information in your page, get their top value
Because this top value is the distance between the node and the top of the screen
You need to store them in a new array
And what you have to do at this time is to judge the array located in the center of the screen in this new array. I set the range of 150-450
Then the data information of the subscript of the data array will be changed through the subscript of the new array, so that it can be played automatically
//自动播放视频getRectInfo:function(list){
let that =this
that.duiListHeight =[]// 定位setTimeout(function(){
for(let i =0; i < that.duiList.length; i++){
var query = uni.createSelectorQuery().in(that);var nodeDef = query.select('#cell'+ i);
nodeDef.boundingClientRect((data)=>{
var tmpHeight = data;
that.duiListHeight.push(tmpHeight.top)
that.duiListHeight.forEach((item, index)=>{
if(item >150&& item <450){
that.currentindex= index
}})}).exec();}},500)},