All Projects → YasinChan → wechat-scroll-linkage

YasinChan / wechat-scroll-linkage

Licence: other
微信小程序列表左右联动效果

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to wechat-scroll-linkage

wxbizdatacrypt
微信小程序加密数据解密算法Go版
Stars: ✭ 132 (+407.69%)
Mutual labels:  minapp, wechat-weapp, wechat-mini-program
Ewa
Enhanced Wechat App Development Toolkit (微信小程序增强开发工具)。不同于 wepy 或者 mpvue,是一个轻量级小程序开发框架。支持原生小程序所有功能,无需学习,极易上手。支持转换为百度/字节跳动/QQ小程序。
Stars: ✭ 160 (+515.38%)
Mutual labels:  wechat-app, wechat-mini-program
Rktk Wxx
软考题库微信小程序 ENJOY
Stars: ✭ 131 (+403.85%)
Mutual labels:  wechat-app, wechat-mini-program
Awesome Wechat Weapp
微信小程序开发资源汇总 💯
Stars: ✭ 36,769 (+141319.23%)
Mutual labels:  minapp, wechat-weapp
Wechat Miniprogram Ar 3d
A WeChat MiniProgram 3D that includes a Panorama Viewer and a 3D Viewer using the device orientation control.
Stars: ✭ 80 (+207.69%)
Mutual labels:  wechat-app, wechat-mini-program
Wx App Painting
微信小程序:涂鸦 (涂鸦、涂鸦照片、像素涂鸦)
Stars: ✭ 98 (+276.92%)
Mutual labels:  wechat-app, wechat-mini-program
Weapp Jump
跳一跳 小程序 源码
Stars: ✭ 173 (+565.38%)
Mutual labels:  wechat-app, wechat-mini-program
Alaweb
一套 Vue 代码,多端可用(H5、小程序、苹果App、安卓App、头条等)。系统含150+页面,200+组件(5端通用),30+元件(每个终端独立完成)
Stars: ✭ 837 (+3119.23%)
Mutual labels:  wechat-app, wechat-mini-program
CatToolBox
猫咪工具箱小程序 微信小程序
Stars: ✭ 20 (-23.08%)
Mutual labels:  wechat-app, wechat-weapp
library-mini-program
基于小程序云开发的图书管理小程序
Stars: ✭ 44 (+69.23%)
Mutual labels:  wechat-weapp, wechat-mini-program
PopRun
跑鸭:这是我的毕业设计,“跑鸭”微信小程序-一款基于校园跑步的社交小程序(实时里程配速、运动路径、整公里提醒、周榜月榜、打卡分享、热门推荐、线上活动、勋章墙、隐私设置),技术栈:Vant-Weapp UI、Laravel+MySQL
Stars: ✭ 64 (+146.15%)
Mutual labels:  wechat-app, wechat-mini-program
Supermarketmini
基于wepy2.x 仿苏宁小店小程序,API采用go开发(已开源),项目正在开发中,欢迎加群:160301726
Stars: ✭ 73 (+180.77%)
Mutual labels:  wechat-app, wechat-mini-program
Gushi lite
古诗文小助手(微信小程序)
Stars: ✭ 61 (+134.62%)
Mutual labels:  wechat-app, wechat-mini-program
Weapp Monument Valley
纪念碑谷 小程序 源码
Stars: ✭ 119 (+357.69%)
Mutual labels:  wechat-app, wechat-mini-program
Mpvue Animated Number
微信小程序 mpvue 数字更新滚动动画组件 / An animated number component for mpvue
Stars: ✭ 33 (+26.92%)
Mutual labels:  wechat-app, wechat-mini-program
CHCharts-wechat
📈A charts component for WeChat mini-app development(一款用于微信小程序开发中的图表组件,使用者可以快速添加并集成到微信小程序开发中).
Stars: ✭ 71 (+173.08%)
Mutual labels:  wechat-app, wechat-mini-program
Weixin Java Miniapp Demo
基于Spring Boot 和 WxJava 实现的微信小程序Java后端Demo
Stars: ✭ 779 (+2896.15%)
Mutual labels:  wechat-app, wechat-mini-program
Masterwechatapp
『微信小程序』优秀教程、轮子、开源项目 资源汇总
Stars: ✭ 826 (+3076.92%)
Mutual labels:  wechat-app, wechat-mini-program
wxapp-weathermin
💬微信小程序-迷你天气 demo
Stars: ✭ 22 (-15.38%)
Mutual labels:  wechat-app, wechat-weapp
cxjslite
程序集市lite版,使用wordpress作为后台生成微信小程序,可用于博客、资讯、自媒体小程序。
Stars: ✭ 17 (-34.62%)
Mutual labels:  wechat-weapp, wechat-mini-program

wechat-scroll-linkage

微信小程序左右联动效果

左边栏点击 button 右侧会跟随滚动到对应的区域; 右测滚动,左侧也会滚动到对应的 button ;

演示

GIF演示

预览

git clone https://github.com/YasinChan/wechat-scroll-linkage.git
# 用微信开发者这工具打开此案例查看效果

实现原理

  1. 数据渲染

    目前我将需要渲染的数据以 json 的形式保存在./utils/constants.js中可参考

  2. 首先需要设置常量,如下图,各个位置暂时命名为 LEFT_ITEM RIGHT_BAR RIGHT_ITEM

    image

  3. 在 onload 阶段,我们需要获取每个右侧分类的 RIGHT_BAR 到顶部的距离,用来做后面的计算。

    getEachRightItemToTop: function () {  // 获取每个右侧的 RIGHT_BAR 到顶部的距离,用来做后面的计算。
        var obj = {};
        var totop = 0;
        obj[constants[0].id] = totop      // 右侧第一类肯定是到顶部的距离为 0
        for (let i = 1; i < (constants.length + 1); i++) {  // 循环来计算每个子类到顶部的高度
            totop += (RIGHT_BAR_HEIGHT + constants[i-1].category.length * RIGHT_ITEM_HEIGHT)
            obj[constants[i] ? constants[i].id : 'last'] = totop    
            // 这个的目的是 例如有两类,最后需要 0-1 1-2 2-3 的数据,所以需要一个不存在的 'last' 项,此项即为第一类加上第二类的高度。
        }
        return obj
    },
    
  4. 现在,我们为左右两侧添加相应的事件

    1. 为左侧列表添加bindtap事件,使右侧滚动到相应的位置

      jumpTo: function (e) {    // 左侧 LEFT_ITEM 的点击事件,点击时,右侧会滚动到对应 RIGHT_BAR
          this.setData({
              toView: e.target.id || e.target.dataset.id,
              currentLeftSelect: e.target.id || e.target.dataset.id
          })
      }
      
    2. 为右侧添加bindscroll事件,用来监听右侧滚动事件,来使左侧列表响应,滚动到相应位置

      rightScroll: function (e) {   // 监听右侧的滚动事件与 eachRightItemToTop 的循环作对比 从而判断当前可视区域为第几类,从而左侧滚动到对应 LEFT_ITEM。
          for (let i = 0; i < this.data.constants.length; i++) {
            let left = this.data.eachRightItemToTop[this.data.constants[i].id]
            let right = this.data.eachRightItemToTop[this.data.constants[i + 1] ? this.data.constants[i+1].id : 'last']
            if (e.detail.scrollTop < right && e.detail.scrollTop >= left) {
              this.setData({
                currentLeftSelect: this.data.constants[i].id,
                leftToTop: LEFT_ITEM_HEIGHT * i
              })
            }
          }
        },
      
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].