当用户“点击”时,在 Mobile Safari 中添加 :hover 效果

发布于 2024-11-30 18:24:08 字数 446 浏览 2 评论 0原文

每当 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浊酒尽余欢 2024-12-07 18:24:08

您是在 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 jQuery

If you are not using UIWebView then we need to define gesture recognizers on the UIView and handle the gestures. i.e. in the gesture handlers make a hover uiview and remove it as the user tap is gone...

橘虞初梦 2024-12-07 18:24:08

我已经弄清楚如何在用户点击 div 区域时触发 :hover 而不使用 javascript。这是使用 display:none;display:block; 完成的。

例如:

<div class="block">
    <p>This content is shown *before* the user hovers over .block or taps .block on an iOS device.</p>
    <div class="mask">
        <p>This content is shown *after* the user hovers over .block or taps .block on an iOS device.</p>
    </div>
</div>

CSS:

.block {
    width:300px;
    height:300px;
    background:black;
}

.mask {
    width:300px;
    height:300px;
    background-color:gray;
    display:none;
}

.block:hover .mask {
    display:block;
}

我发现 :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; and display:block;.

For example:

<div class="block">
    <p>This content is shown *before* the user hovers over .block or taps .block on an iOS device.</p>
    <div class="mask">
        <p>This content is shown *after* the user hovers over .block or taps .block on an iOS device.</p>
    </div>
</div>

CSS:

.block {
    width:300px;
    height:300px;
    background:black;
}

.mask {
    width:300px;
    height:300px;
    background-color:gray;
    display:none;
}

.block:hover .mask {
    display:block;
}

I have found that the :hover only triggers on iOS while using display (as opposed to opacity). Also, CSS transitions ignores display so this cannot be transitioned with CSS. If you'd like the transition for desktop users, you can add opacity:0; and opacity:1;

EDIT: CSS visibility also seems to work.

Thanks for the time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文