提交 dfbf4148 编写于 作者: H hdx

long-list: 滚动联动

上级 80da005e
<template> <template>
<list-view class="list" ref="listView" @scrolltolower="loadData"> <list-view class="list" ref="listView" @scroll="onScroll" @scrolltolower="loadData">
<list-item class="list-item" v-for="(item, index) in dataList" :key="index"> <list-item class="list-item" v-for="(item, index) in dataList" :key="index">
<view class="list-item-icon"> <view class="list-item-icon">
<image class="list-item-icon-image" :src="item.plugin_img_link"></image> <image class="list-item-icon-image" :src="item.plugin_img_link"></image>
...@@ -129,9 +129,10 @@ ...@@ -129,9 +129,10 @@
return result return result
}, },
// onScroll(e : ScrollEvent) { onScroll(e : ScrollEvent) {
// console.log(e.detail.deltaY); // TODO e.detail.deltaY 值不正确
// } this.$emit('pageScroll', e.detail.deltaY)
}
} }
} }
</script> </script>
......
<template> <template>
<scroll-view class="page" :scroll-top="pageScrollTop"> <scroll-view class="page" :scroll-top="pageScrollTop">
<view class="search-bar"> <view class="search-bar" ref="header">
<input placeholder="搜索..." /> <input placeholder="搜索..." />
</view> </view>
<view class="swiper-list"> <view class="swiper-list">
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<swiper class="swiper-view" ref="swiper" :current="swiperIndex" @change="onSwiperChange" <swiper class="swiper-view" ref="swiper" :current="swiperIndex" @change="onSwiperChange"
@transition="onSwiperTransition" @animationfinish="onSwiperAnimationfinish"> @transition="onSwiperTransition" @animationfinish="onSwiperAnimationfinish">
<swiper-item class="swiper-item" v-for="(item, index) in swiperList" :key="index"> <swiper-item class="swiper-item" v-for="(item, index) in swiperList" :key="index">
<long-page ref="longPage" :type="item.type"></long-page> <long-page ref="longPage" :type="item.type" @pageScroll="onSwiperItemPageScroll"></long-page>
</swiper-item> </swiper-item>
</swiper> </swiper>
</view> </view>
...@@ -75,6 +75,7 @@ ...@@ -75,6 +75,7 @@
tabsScrollLeft: 0, tabsScrollLeft: 0,
swiperIndicatorLineLeft: 0, swiperIndicatorLineLeft: 0,
swiperIndicatorLineWidth: 0, swiperIndicatorLineWidth: 0,
$headerHeight: 0,
$lastSwiperIndex: 0, $lastSwiperIndex: 0,
$swiperWidth: 0, $swiperWidth: 0,
$swiperTabsRect: [] as SwiperTabsItem[], $swiperTabsRect: [] as SwiperTabsItem[],
...@@ -87,6 +88,7 @@ ...@@ -87,6 +88,7 @@
}) })
}, },
onReady() { onReady() {
this.$headerHeight = (this.$refs["header"] as INode)?.offsetHeight as number
this.$swiperWidth = (this.$refs["swiper"] as INode)?.offsetWidth as number this.$swiperWidth = (this.$refs["swiper"] as INode)?.offsetWidth as number
this.queryTabItemsSize() this.queryTabItemsSize()
this.setSwiperIndex(0, true) this.setSwiperIndex(0, true)
...@@ -122,6 +124,14 @@ ...@@ -122,6 +124,14 @@
// console.log("onSwiperAnimationfinish", e.detail.current); // console.log("onSwiperAnimationfinish", e.detail.current);
// this.setSwiperIndex(e.detail.current, true); // this.setSwiperIndex(e.detail.current, true);
}, },
onSwiperItemPageScroll(dy : number) {
let top = this.pageScrollTop + dy
if (top > this.$headerHeight) { top = this.$headerHeight }
if (top < 0) { top = 0 }
this.pageScrollTop = top
},
queryTabItemsSize() { queryTabItemsSize() {
this.$swiperTabsRect.length = 0; this.$swiperTabsRect.length = 0;
const tabs = this.$refs["swipertab"] as INode[] const tabs = this.$refs["swipertab"] as INode[]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册