防止 iPad 中的悬停状态
我在 iPad 上查看的页面有一些子链接...现在,当我单击任何这些链接时,我希望相应的链接处于活动状态,并防止
的
$("#leftNav a").mouseleave();
$("#leftNav a").mouseout();
$("#leftNav a").trigger("mouseout");
$("#leftNav a").trigger("mouseleave");
我尝试过
var a=document.getElementsByClassName("searchBySub");
for(var i=0;i<a.length;i++)
{
a[i].ontouchstart=function(e){
console.log("ontouchstart5");
e.preventDefault();
return false;}
}
任何链接出现悬停状态在你说之前,iPad 上没有悬停,我知道这一点......但它确实应用了 :hover 样式;
当用户通过单击某个元素来聚焦该元素时,:hover 应用样式以及 mouseover、mousemove、mousedown、mouseup 并点击事件触发(始终;并且按该顺序)。
所以问题是如何防止某些链接的悬停状态(仅适用于 iPad)? 我无法从 CSS 中删除 :hover 定义,因为相同的 CSS 也用于桌面。
I have some sublinks for a page viewed on the iPad...Now when I click on any of those links, I want the corresponding link to be active and also prevent the hover state from any of the links
I have tried
$("#leftNav a").mouseleave();
$("#leftNav a").mouseout();
$("#leftNav a").trigger("mouseout");
$("#leftNav a").trigger("mouseleave");
I have also tried
var a=document.getElementsByClassName("searchBySub");
for(var i=0;i<a.length;i++)
{
a[i].ontouchstart=function(e){
console.log("ontouchstart5");
e.preventDefault();
return false;}
}
Before you say, there is no hover on iPad, I am aware of that....But it does indeed apply the :hover styles as per;
When the user focuses on an element by single-tapping it, the :hover
styles are applied and the mouseover, mousemove, mousedown, mouseup
and click events fire (always; and in that order).
So question is how do I prevent the hover state on some links, only for the iPad ?
I cannot remove the :hover definition from the CSS as the same CSS is also used for desktop.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 CSS 媒体查询专门为 iPad 设置样式表并覆盖之前的 :hover 定义:
我假设对于 iPad 2,您将需要另一个具有双倍设备宽度的媒体查询。
You can use CSS media queries to set a stylesheet specifically for the iPad and override your :hover definitions from earlier:
I assume that for the iPad 2 you will need another media query with double the device-width.
注意:未经测试
首先创建一个函数来检测用户是否正在使用 iPad。像这样:
如果使用 iPad,请删除所有链接上的 Hoovering 类:
如果您只想在某些链接上应用此功能,您可以这样做:
就像我说的,它未经测试,但我认为您明白了。
希望有帮助!
Note: Not tested
First off create a function for detect if the user is using iPad. Like so:
remove hoovering class on all links if using iPad:
If you only want to apply this on some links you culd do this:
Like i said its not tested but ill think you get the point.
Hope it helps!
不要在有问题的情况下使用 :hover 。使用一个类('.hover')并将该类设置为 ..hover,
正如您所指出的,这在 ipad 上不起作用,这正是您想要的:-)
Don't use :hover in the situations where its a problem. Use a class ('.hover') and set that class on .. hover
as you noted, that doesnt work on an ipad, which is exactly what you want :-)