用于在 JQplot 中悬停/选择点的键盘事件

发布于 2024-12-01 01:54:56 字数 1352 浏览 1 评论 0原文

有没有办法将键盘事件绑定到jqPlot?我试图仅使用左右箭头键将鼠标悬停在绘图上的点上。每个点也应该突出显示。

我知道有一些方法可以单击,双击等。

$('#chart1').bind('jqplotClick', function(ev, gridpos, datapos, neighbor) {
   if (neighbor) {
   }
});

我还实现了shift单击。

$('#chart1').bind('jqplotShiftClick', function(ev, gridpos, datapos, neighbor) {
    if (neighbor) {
    }    
});

定义:

this.onClick = function(ev) {
    // Event passed in is normalized and will have data attribute.
    // Event passed out is unnormalized.
    if (ev.shiftKey) {
        var positions = getEventPosition(ev);
        var p = ev.data.plot;
        var neighbor = checkIntersection(positions.gridPos, p);
        var evt = jQuery.Event('jqplotShiftClick');
        evt.pageX = ev.pageX;
        evt.pageY = ev.pageY;
        $(this).trigger(evt, [positions.gridPos, positions.dataPos, neighbor, p]);
    } else {
        var positions = getEventPosition(ev);
        var p = ev.data.plot;
        var neighbor = checkIntersection(positions.gridPos, p);
        var evt = jQuery.Event('jqplotClick');
        evt.pageX = ev.pageX;
        evt.pageY = ev.pageY;
        $(this).trigger(evt, [positions.gridPos, positions.dataPos, neighbor, p]);
    }
};​

但在所有这些中,都涉及到点击。我希望能够在不实际选择点的情况下产生相同的效果。

如果您有任何想法,请告诉我。

Is there a way to bind keyboard events to jqPlot? I am trying to hover through the points on a plot using only the left and right arrow keys. Also each point should highlight.

I know there are ways to click, double click etc.

$('#chart1').bind('jqplotClick', function(ev, gridpos, datapos, neighbor) {
   if (neighbor) {
   }
});

I have also implemented shift click.

$('#chart1').bind('jqplotShiftClick', function(ev, gridpos, datapos, neighbor) {
    if (neighbor) {
    }    
});

definition:

this.onClick = function(ev) {
    // Event passed in is normalized and will have data attribute.
    // Event passed out is unnormalized.
    if (ev.shiftKey) {
        var positions = getEventPosition(ev);
        var p = ev.data.plot;
        var neighbor = checkIntersection(positions.gridPos, p);
        var evt = jQuery.Event('jqplotShiftClick');
        evt.pageX = ev.pageX;
        evt.pageY = ev.pageY;
        $(this).trigger(evt, [positions.gridPos, positions.dataPos, neighbor, p]);
    } else {
        var positions = getEventPosition(ev);
        var p = ev.data.plot;
        var neighbor = checkIntersection(positions.gridPos, p);
        var evt = jQuery.Event('jqplotClick');
        evt.pageX = ev.pageX;
        evt.pageY = ev.pageY;
        $(this).trigger(evt, [positions.gridPos, positions.dataPos, neighbor, p]);
    }
};​

But in all these, there is a click involved. I want to be able to produce the same effect without actually selecting the point.

Please let me know if you have any ideas.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野心澎湃 2024-12-08 01:54:56

我能想到的唯一方法是将 keydownkeypress 事件附加/绑定到文档本身,并相应地对按键操作进行操作。

这已合并到此处提供的示例中。

不要忘记在结果框架内单击以使用键盘.

The only way I can think of is to attach/bind the event of keydown or keypress to the document itself and act upon a key action accordingly.

This was incorporated into the sample available here.

Do not forget to click inside the Result frame in order to use keyboard.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文