Blogger Information
Blog 67
fans 0
comment 2
visits 71989
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
微信小程序左右导航联动加顶部+插件用的colorui
搁浅
Original
1125 people have browsed it

html代码

  1. <view class="VerticalBox">
  2. <scroll-view class="VerticalNav nav" scroll-y scroll-with-animation scroll-top="{{VerticalNavTop}}" style="height:calc(100vh)"><!-- 如果顶部有内容100vh-顶部高rpx -->
  3. <view class="cu-item {{index==TabCur?'text-coffee cur':''}}" wx:for="{{publicitylist}}" wx:key="index" bindtap='tabSelect' data-id="{{index}}">
  4. {{item.theme}}
  5. </view>
  6. </scroll-view>
  7. <scroll-view class="VerticalMain" scroll-y scroll-with-animation style="height:calc(100vh)" scroll-into-view="main-{{MainCur}}" bindscroll="VerticalMain"><!-- 如果顶部有内容100vh-顶部高rpx -->
  8. <view class="padding-lr-sm padding-top-sm" wx:for="{{publicitylist}}" wx:for-item="themelist" wx:key="index" id="main-{{index}}">
  9. <view class="text-black shadow bg-white">
  10. <view class='padding-sm solid-bottom bg-white text-coffee text-xl text-bold'>
  11. <view class='action'>
  12. {{themelist.theme}} </view>
  13. </view>
  14. <block wx:for="{{themelist.list}}" wx:for-item="minglist" wx:key="index">
  15. <view class='padding-sm bg-white text-black solid-bottom' bindtap="goarticle">
  16. <view class="text-black" style="font-size: 30rpx;">{{minglist.drugname}}</view>
  17. <view class="text-doublecut margin-tb-xs">{{minglist.title}}</view>
  18. <view class="text-sm text-grey bg-white"><block wx:if="{{minglist.fullname}}">{{minglist.fullname}}|</block>名医名方</view>
  19. </view>
  20. </block>
  21. </view>
  22. </view>
  23. <view style="padding-top: 400rpx;"></view>
  24. </scroll-view>
  25. </view>

js代码

  1. data: {
  2. TabCur: 0,//左边导航默认位置
  3. MainCur: 0,//右边导航默认位置
  4. VerticalNavTop: 0,//列表默认高度
  5. load: true,//右边导航滑动定位左边
  6. publicitylist:[//每个数据给个id用于右边导航给左边定位
  7. {
  8. id:0,
  9. theme:'名医名方',
  10. list:[
  11. {drugname:'1资生汤',title:'由各种物质组成的巨型球状天体,叫做星球。星球有一定的形状,有自己的运行轨123456',fullname:'王会书'},
  12. {drugname:'1资生汤2',title:'由各种物质组成的巨型球状天体,叫做星球。星球有一定的形状,有自己的运行轨123456',fullname:''},
  13. {drugname:'1资生汤3',title:'由各种物质组成的巨型球状天体,叫做星球。星球有一定的形状,有自己的运行轨123456',fullname:'王会书2'},
  14. {drugname:'1资生汤4',title:'由各种物质组成的巨型球状天体,叫做星球。星球有一定的形状,有自己的运行轨123456',fullname:'王会书2'},
  15. ]
  16. },
  17. {
  18. id:1,
  19. theme:'授课手书',
  20. list:[
  21. {drugname:'2资生汤',title:'由各种物质组成的巨型球状天体,叫做星球。星球有一定的形状,有自己的运行轨123456',fullname:'王会书'},
  22. {drugname:'2资生汤2',title:'由各种物质组成的巨型球状天体,叫做星球。星球有一定的形状,有自己的运行轨123456',fullname:'王会书2'},
  23. {drugname:'2资生汤3',title:'由各种物质组成的巨型球状天体,叫做星球。星球有一定的形状,有自己的运行轨123456',fullname:'王会书2'},
  24. {drugname:'2资生汤4',title:'由各种物质组成的巨型球状天体,叫做星球。星球有一定的形状,有自己的运行轨123456',fullname:'王会书2'},
  25. ]
  26. },
  27. {
  28. id:2,
  29. theme:'临证医案',
  30. list:[
  31. {drugname:'3资生汤',title:'由各种物质组成的巨型球状天体,叫做星球。星球有一定的形状,有自己的运行轨123456',fullname:'王会书'},
  32. {drugname:'3资生汤2',title:'由各种物质组成的巨型球状天体,叫做星球。星球有一定的形状,有自己的运行轨123456',fullname:'王会书2'},
  33. {drugname:'3资生汤3',title:'由各种物质组成的巨型球状天体,叫做星球。星球有一定的形状,有自己的运行轨123456',fullname:'王会书2'},
  34. {drugname:'3资生汤4',title:'由各种物质组成的巨型球状天体,叫做星球。星球有一定的形状,有自己的运行轨123456',fullname:'王会书2'},
  35. ]
  36. },
  37. {
  38. id:3,
  39. theme:'手书',
  40. list:[
  41. {drugname:'3资生汤',title:'由各种物质组成的巨型球状天体,叫做星球。星球有一定的形状,有自己的运行轨123456',fullname:'王会书'},
  42. {drugname:'3资生汤2',title:'由各种物质组成的巨型球状天体,叫做星球。星球有一定的形状,有自己的运行轨123456',fullname:'王会书2'},
  43. {drugname:'3资生汤3',title:'由各种物质组成的巨型球状天体,叫做星球。星球有一定的形状,有自己的运行轨123456',fullname:'王会书2'},
  44. {drugname:'3资生汤4',title:'由各种物质组成的巨型球状天体,叫做星球。星球有一定的形状,有自己的运行轨123456',fullname:'王会书2'},
  45. ]
  46. },
  47. ],
  48. },
  49. tabSelect(e) {//左边导航按钮
  50. this.setData({
  51. TabCur: e.currentTarget.dataset.id,
  52. MainCur: e.currentTarget.dataset.id,
  53. VerticalNavTop: (e.currentTarget.dataset.id - 1) * 50//左边导航内容距离顶部位置
  54. })
  55. },
  56. VerticalMain(e) {//右边导航滑动事件
  57. let that = this;
  58. let list = this.data.publicitylist;
  59. let tabHeight = 0;
  60. if (this.data.load) {
  61. for (let i = 0; i < list.length; i++) {
  62. let view = wx.createSelectorQuery().select("#main-" + list[i].id);
  63. //如果在子组件里面会获取不到高,要加.in(this)来指定范围。
  64. //let view = wx.createSelectorQuery().in(this).select("#main-" + list[i].id);
  65. view.fields({
  66. size: true
  67. }, res => {
  68. list[i].top = tabHeight;
  69. tabHeight = tabHeight + res.height;
  70. list[i].bottom = tabHeight;
  71. }).exec();
  72. }
  73. that.setData({
  74. load: false,
  75. publicitylist: list
  76. })
  77. }
  78. let scrollTop = e.detail.scrollTop + 20;
  79. for (let i = 0; i < list.length; i++) {
  80. if (scrollTop > list[i].top && scrollTop < list[i].bottom) {console.log();
  81. that.setData({
  82. VerticalNavTop: (list[i].id - 1) * 50,//左边导航内容距离顶部位置
  83. TabCur: list[i].id
  84. })
  85. return false
  86. }
  87. }
  88. },

css代码

  1. /* 下面是左边的导航代码,右边的导航内容可以直接写 */
  2. .VerticalNav.nav {
  3. width: 200rpx;
  4. white-space: initial;
  5. }
  6. .VerticalNav.nav .cu-item {
  7. width: 100%;
  8. text-align: center;
  9. background-color: #fff;
  10. margin: 0;
  11. border: none;
  12. height: 100rpx;
  13. line-height: 100rpx;
  14. position: relative;
  15. }
  16. .VerticalNav.nav .cu-item.cur {
  17. background-color: #f1f1f1;
  18. }
  19. .VerticalNav.nav .cu-item.cur::after {
  20. content: "";
  21. width: 8rpx;
  22. height: 30rpx;
  23. border-radius: 10rpx 0 0 10rpx;
  24. position: absolute;
  25. background-color: currentColor;
  26. top: 0;
  27. right: 0rpx;
  28. bottom: 0;
  29. margin: auto;
  30. }
  31. .VerticalBox{
  32. display: flex;
  33. }
  34. .VerticalMain{
  35. background-color: #f1f1f1;
  36. }

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post