首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >React中的合成触摸事件

React中的合成触摸事件
EN

Stack Overflow用户
提问于 2017-03-16 06:10:18
回答 1查看 2.4K关注 0票数 0

使用下面的.js,在浏览器中调整文本区域的大小不会显示任何触摸事件类型,尽管其他事件按预期工作。

代码语言:javascript
复制
class App extends React.Component{
    constructor(){
        super();
        this.state = {currentEvent: "---"};
        this.update = this.update.bind(this)
    }

    update(e){
        this.setState({currentEvent: e.type})
    }


    render(){
        return (
            <div>
                <textarea cols='30' rows='10' 
                    onKeyPress={this.update}
                    onCopy={this.update}
                    onDoubleClick={this.update}
                    onTouchStart={this.update}
                    onTouchMove={this.update}
                    onTouchEnd={this.update}
                    />
                <h1>{this.state.currentEvent}</h1>
            </div>
        )
    }
}

export default App
EN

回答 1

Stack Overflow用户

发布于 2017-03-16 06:38:06

基本上没有浏览器会触发textarearesize事件。相反,您必须侦听mouseuptouchend事件,这些事件将在用户调整大小后发生。但是,由于只需在textarea中单击即可触发这些事件,因此您可能希望将元素的新大小与旧大小进行比较,以确定它是否实际调整了大小。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42821640

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档