[英]Applying tooltip on mouse hover
I'm putting an image on html5 canvas. 我在html5画布上放了一个图像。
myString = '<img id="img1" class="link1" src = 'img/icon1.png'></img>';
$('#main1' ).append(myString);
$('#main1' + '-link1').fadeIn('slow');
$(".link1").click(function () {
window.location.href = url1;
});
$(".link1").hover(function () {
$('#myDiv').show();
}, function () {
$('#myDiv').hide();
});
The div is : div是:
<div id="myDiv" style="display:none;border: 1px solid black;width: 10px;height:5px;padding: 1px;">
<p>Hello</p>
</div>
Now, on mouse hover the div appears at end of the page. 现在,在鼠标悬停时,div出现在页面的末尾。 I need it to appear just below the image.
我需要它出现在图像下方。 How can I achieve that?
我怎样才能做到这一点?
That depends on the positioning of your 'myDiv' div. 这取决于你的'myDiv'div的定位。
You could just use the <img title="my tooltip text" />
if it's just text in your tooltip. 如果它只是
<img title="my tooltip text" />
您可以使用<img title="my tooltip text" />
。
You can use pageX , pageY from event object to position the div on below the image . 您可以使用事件对象中的pageX,pageY将div放在图像下方。
Please try this link to get the solution http://jsfiddle.net/ZpGS3/14/ . 请尝试此链接以获得解决方案http://jsfiddle.net/ZpGS3/14/ 。
You may try a jQuery plugin called TipTip: 您可以尝试一个名为TipTip的jQuery插件:
http://code.drewwilson.com/entry/tiptip-jquery-plugin http://code.drewwilson.com/entry/tiptip-jquery-plugin
You'll see it's very easy to use and the design is quite great :). 你会发现它很容易使用,而且设计非常棒:)。
You can go to the link and have a try to see if you like it or not. 您可以转到该链接,尝试看看您是否喜欢它。
Considering your example, in order to display the TipTip's tooltip, you'll simply have to do the following: 考虑到您的示例,为了显示TipTip的工具提示,您只需执行以下操作:
$("#img1").tipTip();
$("#img1").tipTip();
title
option of your image: title
选项中: For example: <img id="img1" title="<p>Hello</p>"/>
例如:
<img id="img1" title="<p>Hello</p>"/>
To apply Tooltip on mouseover you should use 要在鼠标悬停时应用工具提示,您应该使用
$('#img1').mouseover(function(){
$(this).attr('title','MY Image Title');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.