forked from gxwebsoft/mp-10550
feat(index):优化轮播图触摸交互支持垂直滚动- 引入touchStartRef记录触摸起始位置- 新增disableSwiper状态控制轮播图禁用
- 设置touchAction样式支持水平垂直滑动 - 调整Swiper组件direction为horizontal -为Swiper.Item添加touchAction样式优化 - 更新CSS样式确保图片点击事件正常- 添加自定义Swiper类名及触摸控制样式 - 启用-webkit-overflow-scrolling提升滚动体验
This commit is contained in:
@@ -14,6 +14,10 @@ const MyPage = () => {
|
||||
const [hotToday, setHotToday] = useState<CmsAd>()
|
||||
const [item, setItem] = useState<CmsArticle>()
|
||||
const [loading, setLoading] = useState(true)
|
||||
// const [disableSwiper, setDisableSwiper] = useState(false)
|
||||
|
||||
// 用于记录触摸开始位置
|
||||
// const touchStartRef = useRef({x: 0, y: 0})
|
||||
|
||||
// 加载数据
|
||||
const loadData = async () => {
|
||||
@@ -98,7 +102,10 @@ const MyPage = () => {
|
||||
return (
|
||||
<View className="flex p-2 justify-between" style={{height: `${carouselHeight}px`}}>
|
||||
{/* 左侧轮播图区域 */}
|
||||
<View style={{width: '50%', height: '100%'}} className="banner-swiper-container">
|
||||
<View
|
||||
style={{width: '50%', height: '100%'}}
|
||||
className="banner-swiper-container"
|
||||
>
|
||||
<Swiper
|
||||
defaultValue={0}
|
||||
height={carouselHeight}
|
||||
@@ -106,13 +113,15 @@ const MyPage = () => {
|
||||
autoPlay
|
||||
duration={3000}
|
||||
style={{
|
||||
height: `${carouselHeight}px`
|
||||
height: `${carouselHeight}px`,
|
||||
touchAction: 'pan-y' // 关键修改:允许垂直滑动
|
||||
}}
|
||||
disableTouch={false}
|
||||
touchAngle={"45"} // 关键修改:设置触摸角度阈值
|
||||
direction="horizontal"
|
||||
className="custom-swiper"
|
||||
>
|
||||
{carouselData && carouselData?.imageList?.map((img, index) => (
|
||||
<Swiper.Item key={index}>
|
||||
<Swiper.Item key={index} style={{ touchAction: 'pan-x pan-y' }}>
|
||||
<Image
|
||||
width="100%"
|
||||
height="100%"
|
||||
@@ -122,7 +131,8 @@ const MyPage = () => {
|
||||
lazyLoad={false}
|
||||
style={{
|
||||
height: `${carouselHeight}px`,
|
||||
borderRadius: '4px'
|
||||
borderRadius: '4px',
|
||||
touchAction: 'manipulation' // 关键修改:优化触摸操作
|
||||
}}
|
||||
/>
|
||||
</Swiper.Item>
|
||||
@@ -181,4 +191,4 @@ const MyPage = () => {
|
||||
)
|
||||
}
|
||||
|
||||
export default MyPage
|
||||
export default MyPage
|
||||
|
||||
Reference in New Issue
Block a user