Skip to content

Mobile #21

@tsukasa1989

Description

@tsukasa1989

Hello,

I needed some mobile scrolling and made the following code.

Functions to add:

onTouchStart : function(e){
        this.touch = {
            start : {
                y : e.touches[0].pageY
            }
        };
    },

    onTouchMove: function(e){
        // calculate new handle position
        this.handle.top += (e.touches[0].pageY - this.touch.start.y) * 0.01;

        this.setHandlePosition();
        this.setContentPosition();

        // prevent default scrolling of the entire document if handle is within [min, max]-range
        if(this.handle.top > this.props.handlePosition.min && this.handle.top < this.props.handlePosition.max){
            e.preventDefault();
        }
    },

Add the following code to the function appendEvents:

// Touch events
        var _this = this;
        this.container[0].addEventListener("touchstart", function(e){
            _this.onTouchStart(e);
        }, false);

        this.container[0].addEventListener("touchmove", function(e){
            e.preventDefault();
            _this.onTouchMove(e);
        }, false);

Good luck!

Tsukasa

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions