简体   繁体   English

Android元素选择问题

[英]Android Element Selection Issues

I'm attempting to make my website tablet friendly and I'm facing a strange issue. 我正在尝试使我的网站平板电脑友好,并且面临一个奇怪的问题。

I am testing on an Android 4.0 tablet with Chrome 30. 我正在使用Chrome 30的Android 4.0平板电脑上进行测试。

I have a fixed modal popover screen. 我有一个固定的模式弹出窗口。 While this screen is on, we don't want to let the user scroll the background so touch events are prevented. 当此屏幕打开时,我们不想让用户滚动背景,因此可以防止触摸事件。 However, in this window we have a scrollable area with overflow:scroll , therefore the touch event is not prevented if the touch start event is detected there. 但是,在此窗口中,我们有一个可滚动区域,其中带有overflow:scroll ,因此,如果在此检测到触摸开始事件,则不会阻止触摸事件。 So far so good - Android responsibly scrolls the area as expected. 到目前为止,一切都很好-Android负责任地滚动了预期的区域。

Problem is, if the user long-presses an element inside the scroll area for about half a second, and only then scrolls - the element where the touch started appears to be selected for a moment. 问题是,如果用户长按滚动区域内的某个元素约半秒钟,然后才滚动-触摸开始的元素似乎被选中了片刻。 That selection disappears after a bit. 该选择很快消失。 But, in case the user scrolls during that bit - the whole page scrolls instead of the scrollable area. 但是,如果用户在该位期间滚动-整个页面将滚动而不是滚动区域。 It's as if the focus is changed. 好像焦点改变了。 What's going on? 这是怎么回事?

I tried to set CSS selection rules on the elements inside but it didn't help. 我试图在内部的元素上设置CSS选择规则,但这没有帮助。

-webkit-touch-callout:none;
-webkit-user-select:none;
-khtml-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
user-select:none;

Every other answer suggests to prevent the touch event which I can't because it's meant to be scrolled. 其他所有答案都建议防止发生触摸事件,因为该事件是要滚动的,所以我不能这样做。 Any ideas what's causing this? 任何想法是什么原因造成的?

OK, I got it. 好,我知道了。

Add cursor:default!important to the above CSS rules. 添加cursor:default!important对上述CSS规则cursor:default!important

I DID come across such a solution but it failed on first try. 我DID遇到过这样的解决方案,但第一次尝试失败。 In my case, the specificity of elements inside the scrollable area was too strong, rendering cursor:default useless and I didn't realize it. 在我的情况下,可滚动区域内元素的特殊性太强,导致cursor:default没有用,而我没有意识到。 I apply this only to mobile devices by detecting the useragent, therefore I can afford dismissing the previous cursor attribute with !important as it won't affect any desktop clients. 我通过检测到用户代理将其仅应用于移动设备,因此我可以用!important消除以前的cursor属性,因为它不会影响任何桌面客户端。 Sweet! 甜!

Still not sure why this worked. 仍不知道为什么这行得通。 If anyone could supply information on how the cursor attribute affects Chrome on Android I will be grateful. 如果有人能提供有关cursor属性如何影响Android上的Chrome的信息,我将不胜感激。

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

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