鼠标悬停时显示Google饼图

时间:2023-01-15 19:48:13

I want to display my chart when the mouse is hover some element. Everything works fine except I can't stop the slideToggle returns its original position.

我想在鼠标悬停某个元素时显示我的图表。一切正常,但我无法阻止slideToggle返回其原始位置。

Once the mouse is "out-of-target" it contracts, but if the mouse still at the chart it should stay appearing.

一旦鼠标“超出目标”,它就会收缩,但如果鼠标仍在图表上,它应该保持显示状态。

$(document).ready(function () {
            $("#test").hover(function () {
                $("#chart_div").slideToggle('slow');
            });
        });  

I made a jsFiddle for this question instead of pasting here the whole bunch of code.

我为这个问题做了一个jsFiddle,而不是在这里粘贴整堆代码。

EDIT

Here is a goal example.

这是一个目标示例。

2 个解决方案

#1


2  

You can do it by defining both mouseenter and mouseleave events like this sample:

您可以通过定义mouseenter和mouseleave事件来完成此操作:

$(document).ready(function() {
    $("#test").mouseenter(function() {
        $("#chart_div").show('slow');
    });
    $(".outerClass").mouseleave(function() {
        if(!$('#chart_div').is(':hover')) {
            $("#chart_div").hide('slow');
        }
    });
});​

Where your html structure should resemble this sample:

您的html结构应该类似于此示例:

<div class="outerClass">
    <div id="test"><strong>TEST.</strong></div>
    <div id="chart_div"></div>
</div>
<div id="another_div">here is out of the pie div</div>

Live Example

#2


1  

The best solution would be to change this to a .click()

最好的解决方案是将其更改为.click()

but if you need the chart to display when you move your mouseover TEST and hide when you move your mouse back over test then you .mouseenter()

但是如果你需要在鼠标移动鼠标时显示图表并在将鼠标移回测试时隐藏,那么你.mouseenter()

$(document).ready(function() {
    $("#test").mouseenter(function() {
        $("#chart_div").slideToggle('slow');
    });
});​

http://jsfiddle.net/fnTXQ/

#1


2  

You can do it by defining both mouseenter and mouseleave events like this sample:

您可以通过定义mouseenter和mouseleave事件来完成此操作:

$(document).ready(function() {
    $("#test").mouseenter(function() {
        $("#chart_div").show('slow');
    });
    $(".outerClass").mouseleave(function() {
        if(!$('#chart_div').is(':hover')) {
            $("#chart_div").hide('slow');
        }
    });
});​

Where your html structure should resemble this sample:

您的html结构应该类似于此示例:

<div class="outerClass">
    <div id="test"><strong>TEST.</strong></div>
    <div id="chart_div"></div>
</div>
<div id="another_div">here is out of the pie div</div>

Live Example

#2


1  

The best solution would be to change this to a .click()

最好的解决方案是将其更改为.click()

but if you need the chart to display when you move your mouseover TEST and hide when you move your mouse back over test then you .mouseenter()

但是如果你需要在鼠标移动鼠标时显示图表并在将鼠标移回测试时隐藏,那么你.mouseenter()

$(document).ready(function() {
    $("#test").mouseenter(function() {
        $("#chart_div").slideToggle('slow');
    });
});​

http://jsfiddle.net/fnTXQ/