小程序scroll左右聯(lián)動

<view style="display:inline-block;height:100%;width:30%;position:fixed;">
  <scroll-view scroll-y="true" scroll-into-view="{{left_id}}" style="height:100%;">
    <block wx:for="{{left}}" wx:key="code">
      <view data-id="{{item.code}}" id="{{item.code}}" style="border-bottom:1rpx solid #808080;height:100rpx;" bindtap="setId">{{item.text}}</view>
    </block>
  </scroll-view>
</view>
<view style="height: 100%;background-color: lightblue;margin-left: 30%;">
  <scroll-view scroll-y="true" scroll-into-view="{{left_id}}" bindscroll='scroll' style="height:1200rpx">
    <block wx:for="{{right}}" wx:key="code">
      <view data-id="{{item.code}}" id="{{item.code}}" bindtap="setId">
        <block wx:for="{{item.list}}" wx:key="id">
          <view id="{{item.id}}" style="height:250rpx;border-bottom:1rpx solid #000;">{{item.text}}</view>
        </block>
      </view>
    </block>
  </scroll-view>
</view>

js

// pages/webview/index.js
Page({

  /**
   * 頁面的初始數(shù)據(jù)
   */
  data: {
    left: [
      { code: 'L1', text: "11" },
      { code: 'L2', text: "22" },
      { code: 'L3', text: "33" },
      { code: 'L4', text: "44" },
      { code: 'L5', text: "55" },
      { code: 'L6', text: "66" },
      { code: 'L7', text: "77" },
      { code: 'L8', text: "88" },
      { code: 'L9', text: "99" },
      { code: 'L10', text: "10" },
      { code: 'L11', text: "11" },
      { code: 'L12', text: "12" },
      { code: 'L13', text: "13" },
      { code: 'L14', text: "14" },
      { code: 'L15', text: "15" }
    ],
    right: [
      {
        code: 'L1', text: "11",
        list: [
          { id: '1', text: "111" },
          { id: '2', text: "1111" }
        ]
      },
      {
        code: 'L2', text: "22",
        list: [
          { id: '1', text: "222" },
          { id: '2', text: "2222" }
        ]
      },
      {
        code: 'L3', text: "33",
        list: [
          { id: '1', text: "333" },
          { id: '2', text: "3333" }
        ]
      },
      {
        code: 'L4', text: "44",
        list: [
          { id: '1', text: "444" },
          { id: '2', text: "4444" }
        ]
      },
      {
        code: 'L5', text: "55",
        list: [
          { id: '1', text: "555" },
          { id: '2', text: "5555" }
        ]
      },
      {
        code: 'L6', text: "66",
        list: [
          { id: '1', text: "666" },
          { id: '2', text: "6666" }
        ]
      },
      {
        code: 'L7', text: "77",
        list: [
          { id: '1', text: "777" },
          { id: '2', text: "7777" }
        ]
      },
      {
        code: 'L8', text: "88",
        list: [
          { id: '1', text: "888" },
          { id: '2', text: "8888" }
        ]
      },
      {
        code: 'L9', text: "99",
        list: [
          { id: '1', text: "999" },
          { id: '2', text: "9999" }
        ]
      },
      {
        code: 'L10', text: "10",
        list: [
          { id: '1', text: "1010" },
          { id: '2', text: "101010" }
        ]
      },
      {
        code: 'L11', text: "11",
        list: [
          { id: '1', text: "1111" },
          { id: '2', text: "111111" }
        ]
      },
      {
        code: 'L12', text: "12",
        list: [
          { id: '1', text: "1212" },
          { id: '2', text: "121212" }
        ]
      },
      {
        code: 'L13', text: "13",
        list: [
          { id: '1', text: "1313" },
          { id: '2', text: "131313" }
        ]
      },
      {
        code: 'L14', text: "14",
        list: [
          { id: '1', text: "1414" },
          { id: '2', text: "141414" }
        ]
      },
      {
        code: 'L15', text: "15",
        list: [
          { id: '1', text: "1515" },
          { id: '2', text: "151515" }
        ]
      },
    ],
    left_id: 'L1'
  },

  /**
   * 生命周期函數(shù)--監(jiān)聽頁面加載
   */
  onLoad: function (options) {
    let query = wx.createSelectorQuery().in(this)
    let heightArr = []
    let s = 0
    this.data.right.forEach(item => {
      // console.log(item)
      // 添加節(jié)點(diǎn)的布局位置的查詢請求
      query.select('#'+item.code).boundingClientRect((rect) => {
        // console.log(rect)
        item.offsetTop = rect.top;
        item.height = rect.height;
      }).exec()
    })
  },

  setId(e){
    // console.log(e)
    const that = this
    that.setData({
      left_id: e.currentTarget.dataset.id
    })
  },

  scroll(e){
    // console.log(e)
    const that = this
    that.data.right.forEach(item => {
      // console.log(item)
      if (e.detail.scrollTop >= (item.offsetTop - 55) && e.detail.scrollTop <= (item.offsetTop - 55 + item.height)) {
        // that.setData({
        //   left_id: item.code
        // })
      }
    })
  }
})
16df2023d051541c (1).gif
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末睛廊,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子饭聚,更是在濱河造成了極大的恐慌偏竟,老刑警劉巖器赞,帶你破解...
    沈念sama閱讀 219,039評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件苞俘,死亡現(xiàn)場離奇詭異胸梆,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)扫责,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,426評論 3 395
  • 文/潘曉璐 我一進(jìn)店門榛鼎,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事者娱÷樟” “怎么了?”我有些...
    開封第一講書人閱讀 165,417評論 0 356
  • 文/不壞的土叔 我叫張陵黄鳍,是天一觀的道長推姻。 經(jīng)常有香客問我,道長框沟,這世上最難降的妖魔是什么藏古? 我笑而不...
    開封第一講書人閱讀 58,868評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮忍燥,結(jié)果婚禮上拧晕,老公的妹妹穿的比我還像新娘。我一直安慰自己灾前,他們只是感情好防症,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,892評論 6 392
  • 文/花漫 我一把揭開白布孟辑。 她就那樣靜靜地躺著哎甲,像睡著了一般。 火紅的嫁衣襯著肌膚如雪饲嗽。 梳的紋絲不亂的頭發(fā)上炭玫,一...
    開封第一講書人閱讀 51,692評論 1 305
  • 那天,我揣著相機(jī)與錄音貌虾,去河邊找鬼吞加。 笑死,一個胖子當(dāng)著我的面吹牛尽狠,可吹牛的內(nèi)容都是我干的衔憨。 我是一名探鬼主播,決...
    沈念sama閱讀 40,416評論 3 419
  • 文/蒼蘭香墨 我猛地睜開眼袄膏,長吁一口氣:“原來是場噩夢啊……” “哼践图!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起沉馆,我...
    開封第一講書人閱讀 39,326評論 0 276
  • 序言:老撾萬榮一對情侶失蹤码党,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后斥黑,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體揖盘,經(jīng)...
    沈念sama閱讀 45,782評論 1 316
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,957評論 3 337
  • 正文 我和宋清朗相戀三年锌奴,在試婚紗的時候發(fā)現(xiàn)自己被綠了兽狭。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,102評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖椭符,靈堂內(nèi)的尸體忽然破棺而出荔燎,到底是詐尸還是另有隱情,我是刑警寧澤销钝,帶...
    沈念sama閱讀 35,790評論 5 346
  • 正文 年R本政府宣布有咨,位于F島的核電站,受9級特大地震影響蒸健,放射性物質(zhì)發(fā)生泄漏座享。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,442評論 3 331
  • 文/蒙蒙 一似忧、第九天 我趴在偏房一處隱蔽的房頂上張望渣叛。 院中可真熱鬧,春花似錦盯捌、人聲如沸淳衙。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,996評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽箫攀。三九已至,卻和暖如春幼衰,著一層夾襖步出監(jiān)牢的瞬間靴跛,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,113評論 1 272
  • 我被黑心中介騙來泰國打工渡嚣, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留梢睛,地道東北人。 一個月前我還...
    沈念sama閱讀 48,332評論 3 373
  • 正文 我出身青樓识椰,卻偏偏與公主長得像绝葡,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子腹鹉,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,044評論 2 355

推薦閱讀更多精彩內(nèi)容