小程序模板网

微信小程序锚点定位楼层跳跃

微信小程序实现楼层锚点跳跃,点击不同的锚点进行位置跳跃: 
利用:scroll-into-view 来实现

效果图如下:

 

WXML:

 

				
  1. [html] view plain copy print?在CODE上查看代码片派生到我的代码片
  2. <scroll-view class="content" scroll-into-view="{{toView}}" scroll-y="true" scroll-with-animation="true">
  3. <view wx:for="{{act_addList}}">
  4. <view class="address_top" id="{{ 'inToView'+item.id}}">{{item.region}}</view>
  5. <view wx:for="{{item.city}}">
  6. <view class="address_bottom">{{item.name}}</view>
  7. </view>
  8. </view>
  9. </scroll-view>
  10.  
  11. <view class="orientation_region">
  12. <view class="orientation">自动定位</view>
  13. <block wx:for="{{orientationList}}" >
  14. <view class="orientation_city" bindtap="scrollToViewFn" data-id="{{item.id}}">{{item.region}}</view>
  15. </block>
  16. </view>
 

WXSS:

 

				
  1. [css] view plain copy print?在CODE上查看代码片派生到我的代码片
  2. page{ height: 100%;}
  3. .content{padding-bottom: 20rpx; box-sizing: border-box; height: 100%;}
  4. .location{width: 100%;}
  5. .location_top{height: 76rpx;line-height: 76rpx; background: #f4f4f4;color: #606660;font-size: 28rpx;padding: 0 20rpx;}
  6. .location_bottom{height: 140rpx;line-height: 140rpx;color: #d91f16;font-size: 28rpx;border-top: 2rpx #ebebeb solid; border-bottom: 2rpx #ebebeb solid;padding: 0 20rpx; align-items: center;display: -webkit-flex;}
  7. .address_top{height: 76rpx;line-height: 76rpx; background: #f4f4f4;color: #999999;font-size: 28rpx;padding: 0 20rpx;}
  8. .address_bottom{height: 88rpx;line-height: 88rpx; background: #fff;color: #000000;font-size: 32rpx;padding: 0 20rpx; border-bottom: 2rpx #ebebeb solid;margin-left: 20rpx;margin-right: 50rpx; }
  9. .location_img{width: 48rpx;height: 48rpx;position: absolute;right: 20rpx;top: 125rpx;}
  10. .add_city{width: 228rpx;height: 60rpx;line-height: 60rpx; text-align: center; border: 2rpx solid #ebebeb; color: #000000;margin-right: 20rpx; }
  11. .add_citying{width: 228rpx;height: 60rpx;line-height: 60rpx; text-align: center; border: 2rpx solid #09bb07; color: #09bb07;margin-right: 20rpx;}
  12. .orientation{white-space:normal;display: inline-block; width: 55rpx;height:58rpx; color: #999; text-align: center;}
  13. .orientation_region{ width: 55rpx;font-size: 20rpx;position: fixed;top: 220rpx; right: 0rpx;}
  14. .orientation_city{height: 50rpx; line-height: 50rpx;color: #000;text-align: center;}
 

JS:

 

				
  1. [javascript] view plain copy print?在CODE上查看代码片派生到我的代码片
  2. Page({
  3.  
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. orientationList: [
  9. { id: "01", region: "东北" },
  10. { id: "02", region: "华北" },
  11. { id: "03", region: "华东" },
  12. { id: "04", region: "华南" },
  13. { id: "05", region: "华中" },
  14. { id: "06", region: "西北" },
  15. { id: "07", region: "西南" }
  16. ],
  17. act_addList: [
  18. {
  19. id: "01", region: "东北地区",
  20. city: [{ id: "0101", name: "白山江源" },
  21. { id: "0102", name: "白山市" },
  22. { id: "0103", name: "宾县" },
  23. { id: "0104", name: "大庆" },
  24. { id: "0105", name: "测试1" },
  25. { id: "0106", name: "测试2" },
  26. { id: "0107", name: "测试3" },
  27. { id: "0108", name: "测试4" },
  28. { id: "0109", name: "测试5" },
  29. {


易优小程序(企业版)+灵活api+前后代码开源 码云仓库:starfork
本文地址:https://www.eyoucms.com/wxmini/doc/course/23680.html 复制链接 如需定制请联系易优客服咨询:800182392 点击咨询
QQ在线咨询