美文网首页
react滑动组件

react滑动组件

作者: 游荡的猫咪 | 来源:发表于2017-06-08 10:10 被阅读0次

三种事件:onTouchStart,onTouchMove, onTouchEnd。

handleStart = (e) => {
        e.preventDefault();     
        this.setState({  
            startX : e.targetTouches[0].clientX,
            startY : e.targetTouches[0].clientY,
            x:0,
            y:0,
        });
    }
    handleTouchMove = (e) => {
        const { startX, startY, width, height } = this.state;//取得初始坐标和屏幕可视宽高        
        this.setState({
            ///都可以来设置实时变化的值,不用用到changedTouches;
            x: e.touches[0].clientX - startX, //当前触摸点-初始坐标取得实时变化值
            y: e.touches[0].clientY - startY,
        });
        
    }
handleTouchEnd = (e) => {
  let xCur = this.state.x;
  let width = window.screen.availWidth;   
  let curIndex = this.state.index;        
    if(xCur > width/5 && curIndex !== 0){
      curIndex -- ;
      $(".sliders").css("left",-curIndex*7.5+"rem")         
      this.setState({
        index: curIndex
      })
      console.log(curIndex)  
    }else if(xCur < -width/5 && curIndex !== 2){
      curIndex ++ ;
      $(".sliders").css("left",-curIndex*7.5+"rem")          
      this.setState({
        index: curIndex
      })
      console.log(curIndex)
    }
}

相关文章

  • react滑动组件

    三种事件:onTouchStart,onTouchMove, onTouchEnd。

  • react-native实现一个简单的标签页组件(react-n

    前言 react-native-scroll-tab-page是一个可滑动的标签页组件。源码react-nativ...

  • 2021-11-09 React-Native PanRe

    最近想封装一个滑动组件给项目其他组件使用,React Native官方文档中就PanResponder的使用有做大...

  • react-native-scrollable-tab-view

    react-native-scrollable-tab-view是一个滑动tab组件,可在tab之间进行切换显示内...

  • React基础

    React包含react元素和react组件 react元素 react组件 react组件分为函数组件和类组件 ...

  • react step组件滑动效果

    主要涉及3个知识点吧 useRef 因为react中操作DOM需要使用 ref 关联 window.scrollT...

  • 组件

    组件是React的基石,所有的React应用程序都是基于组件的。React组件,可以通过React.createC...

  • 列表循环滑动

    很多地方需要滑动列表,比如:排行榜。滑动列表组件: 其中ScrollView,就是控制滑动的组件 Viewport...

  • ReactNative学习笔记(三)Hello World!

    React Native 看起来很像 React,但React Native的基础组件是原生组件 不是web组件。...

  • react 合成事件

    1. 场景 父组件是个左右可滑动的组件,子组件是可左右滑动的图片展示。功能是手指左右滑动时可页面切换,但是在滑动图...

网友评论

      本文标题:react滑动组件

      本文链接:https://www.haomeiwen.com/subject/rqpzfxtx.html