小程序锚点 使用ScrollView和pageScrollTo |
您所在的位置:网站首页 › 微信小程序锚点跳转 › 小程序锚点 使用ScrollView和pageScrollTo |
锚点定位,这次用到的方法有【pageScrollTo,createSelectorQuery】这边总结两个方法: 一.使用wx.pageScrollTo方法 wx.pageScrollTo(Object object) | 微信开放文档 (qq.com) Taro.pageScrollTo(option) | Taro 文档 (jd.com) 方法一 例子: Taro.pageScrollTo({ scrollTop: 800,//需要定位的高度 duration: 300,//过渡时间 selector:"#id"//选择器,css... fail:(res)=>{ console.log(res,'失败'); }, success:(res)=>{ console.log(res,'成功') } }) 方法二: 例子: 左右两边互动,相互控制当前定位 {border:'1px solid #ccc',textAlign:'center',height:200}} onClick={()=handeleScroll('red')}>红 {border:'1px solid #ccc',textAlign:'center',height:200}} onClick={()=handeleScroll('yellow')}>黄 {border:'1px solid #ccc',textAlign:'center',height:200}} onClick={()=handeleScroll('blue')}>蓝 {border:'1px solid #ccc',textAlign:'center',height:200}} onClick={()=handeleScroll('purple')}>紫 {border:'1px solid #ccc',textAlign:'center',height:200}} onClick={()=handeleScroll('black')}>黑 {border:'1px solid #ccc',textAlign:'center',height:200}} onClick={()=handeleScroll('green')}>绿 {border:'1px solid #ccc',textAlign:'center',height:200}} onClick={()=handeleScroll('grey')}>灰 //左边的方法很简单,创建一个函数传入id,保存并放到scrollIntoView里面,id要和右边区域块保持一致 针对于左边控制右边滑动,最简单直观的方法是给左边的list绑定点击事件 通过scrollIntoView【id】属性进行定位 针对右边内容控制对应的颜色 {colorDistrictList.map((item,index)=>{ return {item.name} })} 可以通过onScrollToLower滚动触发 获取当前滚动的高度 ,通过createSelectorQuery获取当前颜色区的高度, const query = Taro.createSelectorQuery() query.selectAll('.scrollRight').boundingClientRect() //selectAll获取全部类名为.scrollRight的高度,select获取类名为.scrollRight的高度 query.selectViewport().scrollOffset() query.exec((res) => { res[0].map((item,index)=>{ if(index |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |