【发布时间】:2019-10-28 14:07:49
【问题描述】:
我有两个按钮左右到一个 div,这个 div 有一个滚动条 我想要做的是,当按住一个按钮 1000 毫秒时 .. 滚动条不断移动(就像我们浏览器中的默认实现一样) 我知道如何使用 setTimeout!但问题出在函数内部
类内
holdRightButton = () => {
// i want to use this element :
// const slider : HTMLElement = this.state.scrollRef.current;
this.setState({
timer : setTimeout(() => {
}, 1000)
})
}
releaseButton = () => {
clearTimeout(this.state.timer);
}
内部渲染():
<Button onMouseDown={this.holdRightButton}
onMouseUp={this.releaseButton}>
<span className="fas fa-chevron-right" />
</Button>
我试图做例如 Element.ScrollBy(1, 0) 但你知道 .. 它只会执行 1 次 我还尝试了一个布尔值,当 onMouseUp 事件被发送但应用程序崩溃时变为 False 有什么解决办法吗?即使完全不同
【问题讨论】:
标签: javascript html css reactjs typescript