zoukankan      html  css  js  c++  java
  • 容器同步滚动

    (function leftRightSyncScoll(){
      //获取DOM
      let left = document.getElementById('left')
      let right = document.getElementById('right')
     
      // 绑定左右滚动事件
      function bindLeft(){
        removeRight()
        left.addEventListener('scroll',scrollLeft)
      }
      function bindRight(){
        removeLeft()
        right.addEventListener('scroll',scrollRight)
      }
      // 移除左右绑定事件
      function removeLeft(){
        left.removeEventListener('scroll',scrollLeft)
      }
      function removeRight(){
        right.removeEventListener('scroll',scrollRight)
      }
      // 左右滚动执行设置scrollTop
      function scrollLeft(){
        let lst = left.scrollTop
        right.scrollTop = lst
      }
      function scrollRight(){
        let rst = right.scrollTop
        left.scrollTop = rst
      }
      //左右添加滚动事件
      left.addEventListener('mouseover', bindLeft)
      right.addEventListener('mouseover',bindRight)
    })()
    

      

  • 相关阅读:
    sql
    字符和字符串处理例子
    如何用火狐设置代理
    数组指针的一个小例子
    (转)数组指针和指针数组的区别
    函数
    (转)C语言指针5分钟教程
    通俗版解释网关,IP地址,ARP欺骗,DDOS攻击
    计算网络地址
    计算机网络性能指标
  • 原文地址:https://www.cnblogs.com/zhenjianyu/p/12965882.html
Copyright © 2011-2022 走看看