【问题标题】:How to keep and hide tooltip on mouse hover and mouse out如何在鼠标悬停和鼠标移出时保留和隐藏工具提示
【发布时间】:2020-11-24 12:43:48
【问题描述】:

我有igx-grid,我在其中使用igxTooltip。当我将鼠标悬停在网格单元上时,工具提示正在显示,当我将鼠标悬停在工具提示上时,它会自动隐藏。我想让它在我将鼠标悬停在工具提示上时保留工具提示,并且当鼠标移出时它应该隐藏。

这是我试过的。

HTML代码:

<div *ngIf="column.isTooltip">
  //cell of grid
  <div class="heightTarget" [igxTooltipTarget]="tooltipRef1">{{ value }}</div>
</div>
<div>
  <div #tooltipRef1="tooltip" igxTooltip>
    //this is tooltip which is showing
    <div class="poiterClass">{{ value }}</div>
  </div>
</div>

CSS代码:

.heightTarget {
  width: 130px;
  overflow: hidden;
  display: inline-block;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pointerClass {
  display: none;
}

.pointerClass :hover {
  display: block;
}

【问题讨论】:

  • 这能回答你的问题吗? Plain JavaScript tooltip
  • 看来igxtooltip 正在处理隐藏和显示工具提示的逻辑。也许你可以覆盖它。其次,你隐藏并显示pointerClass div,而不是我认为你应该尝试使用#tooltipRef1 div。

标签: javascript html css angular


【解决方案1】:

这样的?

var text = document.querySelector(".tooltip");
text.addEventListener("mouseover", function(){
  text.querySelector(".tooltiptext").style.display = "block";
});

text.addEventListener("mouseout", function(){
  text.querySelector(".tooltiptext").style.display = "none";
});
tooltip {
  position: relative;
  display: inline-block;
  border-bottom: 1px dotted black;
}

.tooltip .tooltiptext {
  display:none;
  width: 120px;
  background-color: black;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 5px 0;

  /* Position the tooltip */
  position: absolute;
  z-index: 1;
}

.tooltip:hover .tooltiptext {
  visibility: visible;
}
<p>Move the mouse over the text below:</p>

<div class="tooltip">Hover over me
  <span class="tooltiptext">Tooltip text</span>
</div>

<p>Note that the position of the tooltip text isn't very good. Go back to the tutorial and continue reading on how to position the tooltip in a desirable way.</p>

【讨论】:

  • 纯 JavaScript
  • 我必须写的那个javascript部分?在 TS 文件的 ngOnInit() 方法中。基本上我在角度 8 中尝试它
  • 添加: 到你的 html 的头部。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-02-18
  • 2011-05-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-30
  • 1970-01-01
相关资源
最近更新 更多