当用户“点击”时,在 Mobile Safari 中添加 :hover 效果
每当 Mobile Safari 用户单击 div 区域时,是否可以触发 :hover
事件?
它不一定是链接。实际上,它不能是链接,因为用户将转到另一个网页。
我应用的悬停效果实际上是在 div 上:#div:hover {color:#ccc;}
我希望每当 iPad 或 iPhone 用户点击 div 区域时就会发生这种悬停。
我知道 CSS 片段用于链接的背景颜色: -webkit-tap-highlight-color:rgba(200,0,0,0.4);
但这不适用于我的情况。
例如,如果这可以应用于文本的颜色,那么我可以使用它。
更新:请参阅下面我接受的答案
Is it possible to trigger a :hover
event whenever a Mobile Safari user single taps on a div area?
It does not have to be a link. Actually, it can't be a link because the user will go to another webpage.
The hover effect I have applied is actually on a div : #div:hover {color:#ccc;}
I would like for this hover to happen whenever an iPad or iPhone user single taps on the div area.
I know that piece of CSS exists for the background color of a link:-webkit-tap-highlight-color:rgba(200,0,0,0.4);
But this does not apply to my situation.
If this could apply to the color of the text, for example, then I could use it.
Update: Please see my accepted answer below
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是在 UIWebview 的上下文中谈论这个吗?您可以注入 CSS 或 Javascript,并将其视为任何其他浏览器。如果您这样做,我建议 jQuery
如果您没有使用
UIWebView
那么我们需要在 UIView 上定义手势识别器并处理手势。即在手势处理程序中创建一个悬停 uiview 并在用户点击消失时将其删除......Are you talking about this in context with
UIWebview
? You can inject CSS or Javascript and treat it as any other browser. If you are doing so I would suggest jQueryIf you are not using
UIWebView
then we need to define gesture recognizers on theUIView
and handle the gestures. i.e. in the gesture handlers make a hover uiview and remove it as the user tap is gone...我已经弄清楚如何在用户点击 div 区域时触发 :hover 而不使用 javascript。这是使用
display:none;
和display:block;
完成的。例如:
CSS:
我发现 :hover 仅在使用
display
(而不是opacity
)时在 iOS 上触发。此外,CSS 转换会忽略display
,因此无法使用 CSS 进行转换。如果您希望桌面用户进行转换,可以添加opacity:0;
和opacity:1;
编辑:CSS
visibility
也似乎去工作。谢谢你的时间。
I have figured out how to trigger :hover when a user taps on a div area without using javascript. This is done using
display:none;
anddisplay:block;
.For example:
CSS:
I have found that the :hover only triggers on iOS while using
display
(as opposed toopacity
). Also, CSS transitions ignoresdisplay
so this cannot be transitioned with CSS. If you'd like the transition for desktop users, you can addopacity:0;
andopacity:1;
EDIT: CSS
visibility
also seems to work.Thanks for the time.