【问题标题】:jQuery Popup Tooltip ID on blocks块上的 jQuery 弹出工具提示 ID
【发布时间】:2013-01-04 12:54:10
【问题描述】:

我使用了准备好的jQuery Script for Tooltip(我不是 Javascript 编码员)在我的网站上实现。

问题是如果文本在<a></a> 之间,代码只允许工具提示悬停。把它拿出来不会显示效果。使用 DIV 在<a></a> 之间进行格式化并不是最好的方法。我怎样才能运行效果在<a></a>之外也起作用的Javascript

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>

【问题讨论】:

    标签: jquery hover tooltip


    【解决方案1】:

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

    class='tip_trigger' > class='tip'。

    你可能有一个 div .tip_trigger 和其他带有 .tip 类的标签,它应该可以工作。

    因此,以您为例,问题在于您在“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>
    

    它应该可以正常工作。

    【讨论】:

    • 我还想在悬停效果中显示一些内容。这就是为什么如果我添加任何其他标签它不会显示在里面。示例:jsfiddle.net/mBShz/3
    【解决方案2】:

    例如,您可以使用&lt;span/&gt;

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

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

    See it here.

    【讨论】:

    • 你说得对,它的工作原理是正确的,但如果我把 DIV 放在里面,它就不会显示效果。见这里:jsfiddle.net/mBShz/2
    • @karabey,这是不正确的标记。现在,我意识到在你的问题中我根本无法理解的那句话是你要求在p &gt; a 中添加一个&lt;div&gt;
    • 是的,虽然这是不可能的,但我怎样才能将它从“a”标签中取出并仍然显示效果
    • @karabey,我现在有时间了。您是否设法解决了您的问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-12
    • 1970-01-01
    • 2012-01-15
    • 2023-03-24
    相关资源
    最近更新 更多