jQuery flot mouseleave不适合我

jQuery flot mouseleave does not work for me

本文关键字:不适合 mouseleave flot jQuery      更新时间:2023-09-26

我已经修改了我的jQuery.flot.jsflot.pie.js一点,使鼠标离开效果在我的饼画布。

在第585行flot.pie.js

function onMouseMove(e) {
    triggerClickHoverEvent('plothover', e);
}
function onMouseLeave(e) {
    triggerClickHoverEvent('plotleave', e);
}
function onClick(e) {
    triggerClickHoverEvent('plotclick', e);
}

if (options.series.pie.show && options.grid.hoverable) {
    eventHolder.unbind('mousemove').mousemove(onMouseMove);
    eventHolder.unbind('mouseleave').mouseleave(onMouseLeave);
}
$("#graph1").bind("plothover", pieHover);
$("#graph1").bind("plotleave", pieLeave);
$("#graph1").bind("plotclick", pieClick);
函数mysite.html
function pieHover(event, pos, obj) {
    if (!obj) return;
    var what = obj.series.name;
    $("a[name=" + what + "]").addClass("hover");
    $("#world #" + what + " path", svg.root()).attr("fill", "url(#orange)");
    $("#world #" + what + " path.water", svg.root()).attr("fill", "#92D7E7");
}
function pieLeave(event, pos, obj) {
    if (!obj) return;
    var what = obj.series.name;
    $("a[name=" + what + "]").removeClass("hover");
    $("#world #" + what + " path", svg.root()).attr("fill", "#68CDF2");
    $("#world #" + what + " path.water", svg.root()).attr("fill", "#B9E4EE");
}
function pieClick(event, pos, obj) {
    if (!obj) return;
    percent = parseFloat(obj.series.percent).toFixed(2);
    alert('' + obj.series.label + ': ' + percent + '%');
}

我的pieLeave函数被完全忽略。有什么问题吗?谢谢你的帮助。
更多信息:flot示例

好的,发生了。你不能在绘图上使用mouseleave因为绘图是整个画布容器,唯一的方法是将所有内容绑定到mouseleve并检查对象的na

function pieHover(event, pos, obj) 
    {
    if (!obj) { // if no object (move out of the plot, clear everything)
    $("a").removeClass("hover");
    $("#world g path", svg.root()).attr("fill", "#68CDF2");
    $("#world g path.water", svg.root()).attr("fill", "#B9E4EE");
    //      return;
    }
    else { // clear everything, do something.
    what = obj.series.name;
    $("a").removeClass("hover");
    $("#world g path", svg.root()).attr("fill", "#68CDF2");
    $("#world g path.water", svg.root()).attr("fill", "#B9E4EE");
    $("a[name="+what+"]").addClass("hover");
    $("#world #"+what+" path", svg.root()).attr("fill", "url(#orange)"); 
    $("#world #"+what+" path.water", svg.root()).attr("fill", "#92D7E7");
    }
}