在reactjs 组建中用 hammerjs 绑定的事件,在IOS中点击后会连续执行两次



 var Test = React.createClass({

    componentDidMount: function(){
        var hammer = new Hammer(document.querySelector('button'));
        hammer.on("tap", function(e){
            console.log('111111111');
        });
    },

    render: function(){
        return (
            <div ref="hammer" style={{padding: '100px 0 0 100px'}}>
                <button>test</button>
            </div>
        )
    }
})

React.render(<Test />, document.body)

iOS中点击button,tap事件执行两次

hammerjs 前端 JavaScript react.js reactjs

波塔斯基灬 9 years, 3 months ago

 .on("tap", function(evt) {
  evt.gesture.srcEvent.preventDefault();
});

蒋公剿匪不力 answered 9 years, 3 months ago

Your Answer