简体   繁体   English

jQuery工具提示和鼠标悬停集成

[英]jQuery Tooltip and Mouseover Integration

I'm working on an MIT map of projects for an architectural firm, and trying to figure out how to keep the red dots mouseover state on while the mouse moves over the associated tooltips that pop up. 我正在为一家建筑公司制作MIT项目图,并试图弄清楚当鼠标移到弹出的相关工具提示上时如何保持红点鼠标悬停状态。 Right now the mouseover turns off when the mouse moves to the tooltips. 现在,当鼠标移至工具提示时,鼠标悬停关闭。

Also, when either the dot or the link in the tooltip are clicked, I need the tooltip to clear and turn off. 另外,当单击工具提示中的点或链接时,我需要清除并关闭工具提示。 I noticed on an iPad that after clicking a tooltip link to a project page and then going back to the map page with the back button, the last tooltip for some reason stays stuck open. 我在iPad上注意到,单击工具提示链接到项目页面,然后使用“后退”按钮返回到地图页面后,由于某种原因,最后一个工具提示保持打开状态。 Doesn't seam to be an issue on desktops, but on mobile devices I need it to be cleared when they hit the back button. 在台式机上并不是缝隙问题,但是在移动设备上,当它们按下后退按钮时,我需要清除它。

Here is the site i'm referring to: http://www.digitour360.com/mit/ and the stylesheet is here: http://www.digitour360.com/mit/css/stylesheet.css 这是我指的网站: http : //www.digitour360.com/mit/样式表在此处: http : //www.digitour360.com/mit/css/stylesheet.css

Below is the css code of the circle sprite for each button - i'm trying to somehow tie these to each of the tooltips. 下面是每个按钮的圆形精灵的css代码-我试图以某种方式将它们绑定到每个工具提示。 For example, if the mouse moves over red circle button 11 and then onto the tooltip for button 11, I do not want the red circle hover state to turn off until it leaves the tooltip. 例如,如果鼠标移至红色圆圈按钮11上方,然后移至按钮11的工具提示上,我不希望红色圆圈悬停状态关闭直到它离开工具提示。

#button { background:transparent url(../images/red-circle.png) no-repeat scroll 0px -2px; display:block; height:23px; width:23px; } #button:hover { background-position:0 -25px; opacity: 1; }'

And One more thing, what is the best way to make sure the tooltip is closed when any link is clicked inside of it? 还有一件事,当单击工具提示中的任何链接时,确保其关闭的最佳方法是什么? For some reason on mobile devices, when you finger hits to open the hover state and then you click a link on it, if you hit the back button, the tooltip stays stuck open. 出于某种原因,在移动设备上,当您用手指轻击以打开悬停状态,然后单击其上的链接时,如果您按下“后退”按钮,则工具提示将保持打开状态。

You can use the events onShow and onHide on each of your tooltips and do modifications to the trigger object. 您可以在每个工具提示上使用事件onShow和onHide,并对触发对象进行修改。 I'll show this to you with your code. 我将用您的代码向您展示。 Here are your trigger button divs: 这是您的触发按钮div:

<div id="eleven_div" class="button-eleven" style="display: block; ">
    <a href="projects/gantt/" id="button">Button 11</a>
</div>
<div id="ten_div" class="button-ten" style="display: block; ">
    <a href="projects/table/" id="button">Button 10</a>
</div>
...

And the corresponding javascript: 和相应的javascript:

$(".button-one").tooltip({
    position: "center right",
    delay:300,
    effect: 'slide',
    direction:'right',
    offset: [30, -12],
    slideOffset: 30,
    slideFade:'true',
    slideInSpeed:350,
    slideOutSpeed:250
});

$(".button-two").tooltip({ 
    position: "bottom left",
    delay:300,
    effect: 'slide',
    direction:'left',
    offset: [-34, 20],
    slideOffset: 30,
    slideFade:'true',
    slideInSpeed:350,
    slideOutSpeed:250
});
...

First you have the attribute id="button" inside each of your a-tags inside the divs. 首先,您在div中的每个a标签中都有id =“ button”属性。 It is absolutly wrong. 这是绝对错误的。 Ids must not occur twice. ID不得出现两次。 So better change this into classes: 因此最好将其更改为类:

<div id="eleven_div" class="button-eleven" style="display: block; ">
    <a href="projects/gantt/" class="button">Button 11</a>
</div>
<div id="ten_div" class="button-ten" style="display: block; ">
    <a href="projects/table/" class="button">Button 10</a>
</div>

Now place the callback function for the red dots to be shown. 现在放置要显示的红点的回调函数。 The function is called every time a tooltip is shown or will be hide again. 每次显示工具提示时都会调用该函数,否则将再次隐藏该提示。 And it adds or removes a class to the a-tag inside the triggering div. 并在触发div内的a-tag中添加或删除类。 New code: 新代码:

function hovering()
{
    this.getTrigger().find("a").first().toggleClass("hovered");
}

$(document).ready(function() {

    $(".button-one").tooltip({
        position: "center right",
        delay:300,
        effect: 'slide',
        direction:'right',
        offset: [30, -12],
        slideOffset: 30,
        slideFade:'true',
        slideInSpeed:350,
        slideOutSpeed:250,
        onShow: hovering,
        onHide: hovering
    });

    $(".button-two").tooltip({ 
        position: "bottom left",
        delay:300,
        effect: 'slide',
        direction:'left',
        offset: [-34, 20],
        slideOffset: 30,
        slideFade:'true',
        slideInSpeed:350,
        slideOutSpeed:250,
        onShow: hovering,
        onHide: hovering
    });
...

At last change your CSS code, where the styles for #button are located into this: 最后,更改您的CSS代码,其中#button的样式位于其中:

.button {
    background:transparent url(../images/red-circle.png) no-repeat scroll 0px -2px;
    display:block;
    height:23px;
    width:23px;
    overflow:hidden;
    text-indent:-999em;
    cursor:pointer;
    opacity: 1;
    -webkit-transition: opacity 1s;
    -moz-transition: opacity 1s;
    -o-transition: opacity 1s;
}

/**
 * mouseover state, 
 * elements with the "hovered" class now behave
 * like ones in mouseover state
 */
.button:hover, .button.hovered{
    background-position:0 -25px;    
    opacity: 1;
}

/* clicked state */
.button:focus {
    background-position:0 -25px;
}

To have the tooltip getting closed when a link is clicked, put this code after your tooltip definitions: 要在单击链接时关闭工具提示,请将以下代码放在工具提示定义之后:

$(".tooltip, .tooltip-brite, ... all your tooltip-classes").live("click", function() {  
    $(this).prev().tooltip().hide();
});

$(".button-two, .button-one, ... all your button-classes").live("click", function() {   
    $(this).tooltip().hide();
});

This will close the tooltip when ether the div with the red dot indside or the tooltip box is clicked. 当点击带有红点的div或工具提示框时,这将关闭工具提示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM