简体   繁体   English

单击时防止隐藏Abbr工具提示

[英]Prevent Hiding Abbr Tooltip on Click

When I use the <abbr> element, I typically add a dotted border under the abbreviation to indicate that more information is available: 当我使用<abbr>元素时,我通常在缩写下添加一个虚线边框,表示有更多信息可用:

在此输入图像描述

The tooltip takes around two seconds to appear*, and since it's not immediate, it seems natural that a user would click on the text (especially since it looks similar to a link). 工具提示需要大约两秒才能显示*,并且由于它不是即时的,因此用户点击文本似乎很自然(特别是因为它看起来类似于链接)。

However, clicking on the abbreviation hides the tooltip if it's already visible and prevents it from ever appearing if it hasn't yet been revealed. 但是,如果工具提示已经可见,则单击该缩写会隐藏工具提示,并防止它在尚未显示时出现。

Is there a way to prevent this click behavior? 有没有办法防止这种点击行为?

I tried the obvious with no luck: 我没有运气地尝试了明显的事情:

$('abbr').on('click', function(e) { e.preventDefault(); });

(*) - 2 seconds in Chrome, about 1 second in Firefox (*) - 在Chrome中为2秒,在Firefox中为1秒左右

Here is the best option I could find. 这是我能找到的最佳选择。 Provided by Andres Ilich on this SO question . Andres Ilich提供了这个问题

(The question he answered doesn't pertain to this question but the way he structure this element is actually solving your problem.)(This is not my work, Andres Ilich found this answer, just sharing the knowledge :} For my version refer to the bottom) (他回答的问题不属于这个问题,但他构建这个元素的方式实际上解决了你的问题。)(这不是我的工作,Andres Ilich找到了这个答案,只是分享知识:}对于我的版本,请参考底端)

What he is doing is styling the a property with the use of pseudo elements. 他正在做的是使用伪元素为a属性设置样式。 If the element is clicked it does not hide the :after element and is a nice work around to this. 如果单击该元素,它不会隐藏:after元素,并且是一个很好的解决方法。

(He is using the title value to input into the content: ""; which was pretty cool!) (他使用标题值输入content: "";这非常酷!)

Here is the code that adds a new title in: 以下是添加新标题的代码:

a[title]:hover:after {
  content: attr(title);
  padding: 4px 8px;
  color: #333;
  position: absolute;
  left: 0;
  top: 100%;
  white-space: nowrap;
  z-index: 20;
  -moz-border-radius: 5px;
  -webkit-border-radius: 5px;
  border-radius: 5px;
  -moz-box-shadow: 0px 0px 4px #222;
  -webkit-box-shadow: 0px 0px 4px #222;
  box-shadow: 0px 0px 4px #222;
  background-image: -moz-linear-gradient(top, #eeeeee, #cccccc);
  background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #eeeeee),color-stop(1, #cccccc));
  background-image: -webkit-linear-gradient(top, #eeeeee, #cccccc);
  background-image: -moz-linear-gradient(top, #eeeeee, #cccccc);
  background-image: -ms-linear-gradient(top, #eeeeee, #cccccc);
  background-image: -o-linear-gradient(top, #eeeeee, #cccccc);
}

His Fiddle: JSFIDDLE 他的小提琴: JSFIDDLE

The only problem from this is the basic title still shows but I could not find any better workaround for this. 唯一的问题是基本标题仍然显示但我找不到任何更好的解决方法。 The only other option that does not use the title property is the suggestion I left as a comment. 唯一不使用title属性的其他选项是我作为评论留下的建议。

This is my version of using the value property instead of the title to add the value in. This does not have two tool-tips poping in and still gets the desired effect. 这是我使用value属性而不是title来添加值的版本。​​这没有两个工具提示弹出并仍然获得所需的效果。

<a href="#" value="This is another link">Mauris placerat</a>

My Fiddle: JSFIDDLE 我的小提琴: JSFIDDLE

Cheers! 干杯!

I think the only way to get what you want would be to replace the default tooltip action. 我认为获得所需内容的唯一方法是替换默认的工具提示操作。 Josh Powell's post includes a nice CSS solution. Josh Powell的帖子包括一个很好的CSS解决方案。 There are javascript solutions such as: http://jqueryui.com/tooltip/ 有javascript解决方案,例如: http//jqueryui.com/tooltip/

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

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