【问题标题】:How to show an image in tooltip?如何在工具提示中显示图像?
【发布时间】:2019-06-03 23:44:02
【问题描述】:

当您将鼠标放在链接上时,我想在工具提示中显示图像。我正在使用 HTML、CSS 和 JAVASCRIPT/JQUERY。我将图像保存在一个文件夹中,因此我从 localhost 引用它。

我尝试通过 JQuery 设置工具提示的内容:

$(document).ready(function() {
    $('#informe').tooltip("option","content","<img src='images/reports/informeInversiones.PNG' />");
    $('#informe').tooltip("option","html","true");
    $('#informe').tooltip("option","animated","fade");
    $('#informe').tooltip("option","placement","bottom");
});

我已经尝试在纯 HTML 中设置工具提示的内容:

<td colspan="2" id="informe" data-toggle="tooltip" title="<img src='images/reports/informeInversiones.PNG'/>"><p><i class="fas fa-download"></i><a id="save"> Generar Informe</a></p></td>

然后,在 JQuery 中:

$(document).ready(function() {
    $('#informe').tooltip("option","html","true");
    $('#informe').tooltip("option","animated","fade");
    $('#informe').tooltip("option","placement","bottom");
});

我有一个链接,它在 onclick 上调用一个下载 PDF 的 JS 函数。我希望当您将鼠标放在链接上时,它会显示您将要生成的 PDF 的预览(简单图像)。我已经尝试过在此页面的其他问题中看到的解决方案,但它们不起作用。

这就是我处理链接的方式:

<td colspan="2"><p><i class="fas fa-download"></i><a href="#" id="informe" title="">Generar Informe</a></p></td>

这是 JQuery:

$('#informe').tooltip({content: "<img src='images/reports/informeInversiones.PNG'/>"});

我什至尝试在 content: 中输入简单的文本,但它甚至没有显示工具提示。

【问题讨论】:

标签: javascript jquery html jspdf


【解决方案1】:

试试这个。

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $(document).ready(function() {
  	$("#content").html('<a id="magilla" href="#" title="" >Magilla Gorilla</a>');
   	$("#content #magilla").tooltip({ content: '<img src="https://i.etsystatic.com/18461744/r/il/8cc961/1660161853/il_794xN.1660161853_sohi.jpg" />' }); 

	});
  </script>
</head>
<body>

<div id="content">    
</div>

</body>
</html>

【讨论】:

  • 我想用JQuery实现
【解决方案2】:

这是链接上的图像工具提示的截图。我相信您可以将此代码用于您的案例

a.tooltip {outline:none; }
a.tooltip strong {line-height:30px;}
a.tooltip:hover {text-decoration:none;} 
a.tooltip span {
    z-index:10;display:none; padding:14px 20px;
    margin-top:60px; margin-left:-160px;
    width:300px; line-height:16px;
}
a.tooltip:hover span{
    display:inline; position:absolute; 
    border:2px solid #FFF;  color:#EEE;
    background:#333 url(http://www.menucool.com/tooltip/cssttp/css-tooltip-gradient-bg.png) repeat-x 0 0;
}

.callout {z-index:20;position:absolute;border:0;top:-14px;left:120px;}
    
/*CSS3 extras*/
a.tooltip span
{
    border-radius:2px;        
    box-shadow: 0px 0px 8px 4px #666;
    /*opacity: 0.8;*/
}
<a href="https://codepen.io/anon/pen/rgPKvy" class="tooltip">
    Link
    <span>
        <img class="callout" src="https://freefrontend.com/assets/img/css-tooltips/pure-css-tooltips.png" />
        <img src="https://freefrontend.com/assets/img/css-tooltips/pure-css-tooltips.png" style="float:right;" />
        <strong>CSS only Tooltip</strong><br />
        Pure CSS popup tooltips with clean semantic XHTML.
    </span>
</a>

【讨论】:

  • 它不起作用。它不显示链接的标签(“一般通知”)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-10-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多