0

我使用了现成的jQuery Script for Tooltip(我不是 Javascript Coder)在我的网站上实现。

问题是代码只允许工具提示悬停如果文本在<a></a>. 把它拿出来不会显示效果。<a></a>与 DIV之间进行格式化并不是最好的方法。我如何运行效果也可以在外部运行的 Javascript<a></a>

Javascript

<script type="text/javascript">
$(document).ready(function() {
    //Tooltips
    $(".tip_trigger").hover(function(){
        tip = $(this).find('.tip');
        tip.show(); //Show tooltip
    }, function() {
        tip.hide(); //Hide tooltip        
    }).mousemove(function(e) {
        var mousex = e.pageX + 20; //Get X coodrinates
        var mousey = e.pageY + 20; //Get Y coordinates
        var tipWidth = tip.width(); //Find width of tooltip
        var tipHeight = tip.height(); //Find height of tooltip

        //Distance of element from the right edge of viewport
        var tipVisX = $(window).width() - (mousex + tipWidth);
        //Distance of element from the bottom of viewport
        var tipVisY = $(window).height() - (mousey + tipHeight);

        if ( tipVisX < 20 ) { //If tooltip exceeds the X coordinate of viewport
            mousex = e.pageX - tipWidth - 20;
        } if ( tipVisY < 20 ) { //If tooltip exceeds the Y coordinate of viewport
            mousey = e.pageY - tipHeight - 20;
        } 
        tip.css({  top: mousey, left: mousex });
    });
});

</script>

CSS

.tip {
    color: #fff;
    background:#1d1d1d;
    display:none; /*--Hides by default--*/
    padding:10px;
    position:absolute;    z-index:1000;
    -webkit-border-radius: 3px;
    -moz-border-radius: 3px;
    border-radius: 3px;
}

的HTML

<p>Text<a class="tip_trigger" href="#">MouseOver<span class="tip">
<img src="image.jpg" />Show as MouseOver Effect</span></a></p>
4

2 回答 2

0

例如,您可以使用<span/>.

从技术上讲,只要您将类名放在tip_trigger那里,它就会接受任何类型的元素。

<p>
    Text
    <span class="tip_trigger">MouseOver
        <span class="tip"><img src="image.jpg" />Show as MouseOver Effect</span>
    </span>
</p>​

看这里。

于 2013-01-04T13:04:40.630 回答
0

我只是快速查看了您的代码,一切似乎都很好。告诉您工具提示是什么或不是什么的不是锚标记,而是以下结构:

类='tip_trigger' > 类='tip'。

您可能在 .tip 类中有一个 div .tip_trigger 和其他标签,它应该可以工作。

因此,以您为例,问题在于您在“a”标签内使用 .tip_trigger,但您可以在“p”标签内使用它,如下所示:

<p class="tip_trigger"><a href="#">MouseOver<span class="tip">
<img src="image.jpg" />Show as MouseOver Effect</span>Text</a></p>

它应该可以正常工作。

于 2013-01-04T13:07:26.383 回答