从iphone上的safari打开时,点击事件无法在手机上运行
在react类组件中,当打开菜单时,我触发窗口上的click事件监听器。它在除Iphone Safari之外的任何地方都能正常工作
toggleMenu = async() => {
if (this.state.isOpen) {
this.handleCloseMenu();
} else {
await this.setState({
isOpen: true
});
window.addEventListener('click', this.handleClick);
disableBodyScroll(this.targetElement);
}
};
handleClick = ({
path
}: E) => {
const btnClicked = path.find(node => node === this.hamburgerBtn.current);
if (!btnClicked) {
const menuClicked = path.find(node => node === this.targetElement.current);
if (!menuClicked) {
this.handleCloseMenu();
}
}
};
单击是鼠标事件。仍然没有鼠标在Iphone上没有鼠标事件。你必须使用这样的触摸板:
document.body.addEventListener('touchstart', function(e){
alert(e.changedTouches[0].pageX) // alert pageX coordinate of touch point
}, false);