schovi / react-iscroll

React component for wrapping iScroll http://iscrolljs.com/
MIT License
236 stars 60 forks source link

about scrollTo() ‘ question #25

Closed hackerslizc closed 8 years ago

hackerslizc commented 8 years ago
import iScroll from 'iscroll/build/iscroll-probe';
import ReactIScroll from 'react-iscroll';

<ReactIScroll
    id="reactIScroll"
    ref="reactIScroll"
    iScroll={iScroll}
    onScrollEnd = {this.onScrollEnd.bind(this)}
    onScroll = {this.onScroll.bind(this)}
    options={{
        useTransition:true,
        mouseWheel: false,
        momentum: true,
        scrollbars: false,
        scrollY:true,
        scrollX:false,
        startY:scrollY
    }}>
    <div id="positionDom" className={ _Bottom ? 'hasBottom' : ''} ref="positionDom">
    {
        _list
    }
    </div>
</ReactIScroll>

gotoTopHandler(){
        var reactscroll = this.refs.reactIScroll;

        **_# PS: i want use  scrollTo() back Top like reactIScroll.scrollTo(0,0), can you tall me ,how can I do?_**

        console.log(reactscroll); 
        // reactscroll.props.iScroll.prototype.scrollTo(0,0,1000)
    }

    gotoTop (){
        return (<Tappable className="animated fadeInUp goto-top zindex-1000" component="button" onTap={this.gotoTopHandler.bind(this)}>
                    <div className="goto-top-inner">
                      <img src="../img/goto-top.png" alt=""/>
                    </div>
                </Tappable>)
    }

i want use scrollTo() back Top like reactIScroll.scrollTo(0,0), can you tall me ,how can I do?

schovi commented 8 years ago

@hackerslizc

API for that https://github.com/schovi/react-iscroll#function-componentwithiscrollwaitforinit-callback

Usage with your case:

gotoTopHandler(){
  var reactscroll = this.refs.reactIScroll;

  reactscroll.withIScroll(function(iScroll) {
    // iScroll is now instance of iScroll and not the component
    iScroll.scrollTo(0,0)
  })
}
schovi commented 8 years ago

Changed readme with your example. It is more self explain :)

hackerslizc commented 7 years ago

thanks for your help。