简体   繁体   English

在Three.js演示中无法通过触摸选择超链接

[英]Hyperlinks not selectable by touch in Three.js demo

Just testing out a recent Three.js tutorial @ https://tympanus.net/Tutorials/StickyImageEffect/ and I've discovered a few issues that have stumped me while attempting to debug. 刚刚测试了最近的Three.js教程@ https://tympanus.net/Tutorials/StickyImageEffect/ ,我发现了一些尝试调试时困扰我的问题。

Firstly, while testing on an iPad and a couple Smartphones hyperlinks are seemingly active but unresponsive to touch & tap. 首先,在iPad和几个智能手机上进行测试时,超链接似乎处于活动状态,但对触摸和点击无响应。 It seems the "sticky" effect/three.js has total control over the viewport and will not allow touch based devices access to links. 似乎“粘性”效果/three.js完全控制了视口,并且不允许基于触摸的设备访问链接。

What would need to be augmented to allow the selecting of links and in the process also ignore the triggering of the "sticky" effect when doing so? 需要增加什么以允许选择链接,并且在此过程中还忽略了“粘滞”效应的触发?

Secondly, when viewing on an iPad in landscape orientation there is a small gap at the top of the viewport. 其次,以横向观看iPad时,视口顶部会有一个小缝隙。

Would this at all be related to the cursor, which is not in use on touch devices? 这是否与触摸设备上未使用的光标有关?

I would search through the code looking for 'touchstart' and seeing if preventDefault is called. 我将在代码中搜索 “ touchstart”,并查看是否preventDefault It is . 是的

One solution might be to add your own touchstart handler for <a> tags 一种解决方案是为<a>标签添加您自己的touchstart处理程序

Let's test 让我们测试

 document.querySelector('#outer').addEventListener('touchstart', (e) => { e.preventDefault(); }); 
 #outer { padding: 2em; background: #EEE; } 
 <div id="outer"> is <a href="https://stackoverflow.com">this link</a> touchable </div> 

The code above seems to prevent the link from working. 上面的代码似乎阻止了链接的工作。

Adding our own event handler to the links themselves and tell them not to propagate. 将我们自己的事件处理程序添加到链接本身,并告诉它们不要传播。 That way they won't be passed on to the element containing them, the that is calling preventDefault and preventing the default thing (following the link) from happening 这样,它们将不会传递给包含它们的元素,即调用preventDefault并防止发生默认情况(跟随链接)

 document.querySelector('#outer').addEventListener('touchstart', (e) => { e.preventDefault(); }); document.querySelectorAll('a').forEach((elem) => { elem.addEventListener('touchstart', stopPropagation); elem.addEventListener('touchmove', stopPropagation); elem.addEventListener('touchend', stopPropagation); }); function stopPropagation(e) { e.stopPropagation(); } 
 #outer { padding: 2em; background: #EEE; } 
 <div id="outer"> is <a href="https://stackoverflow.com/">this link</a> touchable </div> 

It seems to work for me. 似乎为我工作。

No idea about the gap. 不知道差距。 Don't have an iPad to repo and it doesn't seem to repo in the iPad emulation of the Chrome Devtools 没有要回购的iPad,并且在Chrome Devtools的iPad模拟中似乎也没有回购协议

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM