自定义工具提示的基本思想,使用纯Javascript [英] basic idea of a custom tooltip, using pure Javascript
问题描述
我需要使用纯 Javascript
代码创建自定义工具提示的基本想法;
I need basic idea of creating a custom tooltip using pure Javascript
code;
我是什么想要:
例如:
<a href="#" onmousemover="tooltip('text')">Link Text</a>
和 onmouseover
我想显示一个自定义工具提示固定位置
基于< a>
的元素位置
,从开始:0
或从左:0
< ; a>
元素;
And onmouseover
I want to display a custom tooltip with fixed position
based on <a>
's element position
, to start from right:0
or from left:0
of the <a>
element;
推荐答案
当用户搜索<$ c时出现此问题$ c>自定义工具提示,我想添加bootstrap的JS工具提示,虽然你已经提到了纯javascript 。因此从某种意义上说,这个答案只是为了给未来的读者提供另一个很好的选择。
As this question comes up when a user searches for custom tooltip
, I would like to add the bootstrap's JS tooltip, although you have mentioned pure javascript. So in a sense this answer is only to give the future readers another nice option to work with.
看看这里了解如何使用bootstrap tooltip插件。并且此处了解使用Bootstrap的JS工具提示时可供选择的方法和方法。
Take a look here for how to use bootstrap tooltip plugin. And here to learn about the options and methods available at your disposal when using Bootstrap's JS Tooltip.
我仍然从他们的网站给出 tryit
:
Still I am giving the tryit
from their site here:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<style>
/* Tooltip */
.test + .tooltip > .tooltip-inner {
background-color: #73AD21;
color: #FFFFFF;
border: 1px solid green;
padding: 15px;
font-size: 20px;
}
/* Tooltip on top */
.test + .tooltip.top > .tooltip-arrow {
border-top: 5px solid green;
}
/* Tooltip on bottom */
.test + .tooltip.bottom > .tooltip-arrow {
border-bottom: 5px solid blue;
}
/* Tooltip on left */
.test + .tooltip.left > .tooltip-arrow {
border-left: 5px solid red;
}
/* Tooltip on right */
.test + .tooltip.right > .tooltip-arrow {
border-right: 5px solid black;
}
</style>
</head>
<body>
<div class="container">
<h3>Tooltip CSS Example</h3>
<ul class="list-inline">
<li><a class="test" href="#" data-toggle="tooltip" data-placement="top" title="Hooray!">Top</a></li>
<li><a class="test" href="#" data-toggle="tooltip" data-placement="bottom" title="Hooray!">Bottom</a></li>
<li><a class="test" href="#" data-toggle="tooltip" data-placement="left" title="Hooray!">Left</a></li>
<li><a class="test" href="#" data-toggle="tooltip" data-placement="right" title="Hooray!">Right</a></li>
</ul>
</div>
<script>
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
});
</script>
</body>
</html>
PS :在您选择此答案之前,请不要回答OP,请注意我的意图是仅对未来的读者有所帮助,因为搜索自定义工具提示
会导致此处。
P.S.: Before you downvote for this answer not being an answer to the OP, please note that I intended this to be of help to future readers only, since a search for custom tooltip
leads here.
这篇关于自定义工具提示的基本思想,使用纯Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!