Javascript -webkit-tap-highlight-color: rgba(0,0,0,0); 在 div 上?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1974687/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-22 22:11:36  来源:igfitidea点击:

-webkit-tap-highlight-color: rgba(0,0,0,0); on a div?

javascriptiphonecssjavascript-eventswebkit

提问by tarnfeld

Is there any way to apply this to a div?

有什么方法可以将其应用于 div 吗?

回答by tahdhaze09

Are you writing for iPhone/Smartphone websites? If so, then yes. But you'll probably only see the results on your phone/simulator. I think that this element can only be used on links or javascript elements. The div would have to be affected by some kind of scripting, or be a link.

你在为 iPhone/智能手机网站写作吗?如果是这样,那么是的。但您可能只会在手机/模拟器上看到结果。我认为这个元素只能用于链接或 javascript 元素。div 必须受到某种脚本的影响,或者是一个链接。

https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariWebContent/AdjustingtheTextSize/AdjustingtheTextSize.html

https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariWebContent/AdjustingtheTextSize/AdjustingtheTextSize.html

<!DOCTYPE HTML>
<html>
  <head>
    <title>Highlighting Elements</title>
     <style type="text/css">
      .borderImage
        {
          -webkit-tap-highlight-color:rgba(0,0,0,0);

        }       
      </style>
    </head>
<body>
   <div class="borderImage">
     <a href="#">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum non felis risus, tristique luctus lacus. Vestibulum non aliquam arcu. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent eleifend augue a ligula ornare quis lacinia risus ullamcorper.
     </a>
   </div>
</body>
</html>

回答by Tom Vos

I applied this to all (*) of my html objects for my iphone web-app.

我将此应用于我的 iphone 网络应用程序的所有 (*) html 对象。

Simply add this to your css code:

只需将其添加到您的 css 代码中:

*{
/* Prevent any object from being highlighted upon touch event*/
-webkit-tap-highlight-color: rgba(0,0,0,0); }

I used jQuery mobile to add and handle touchstart and touchend events to my buttons, which handles the background-image of my buttons (actually these are divs), so it looks like they are pressed down on touchstart.

我使用 jQuery mobile 添加和处理我的按钮的 touchstart 和 touchend 事件,它们处理我的按钮的背景图像(实际上这些是divs),所以看起来它们在 touchstart 上被按下。

回答by John Doe

This should work:

这应该有效:

-webkit-tap-highlight-color:transparent