1

我想将qtip与 cytoscape.js 一起使用,以在使用 cytoscape.js 创建的图形中鼠标悬停事件的节点中显示工具提示。我已将以下代码放入 ready: function() 中,如下所示:

      cy.on('mouseover','node',function (event) {

        var eid = $(this).data('id');

        $(this).qtip({
            overwrite: false,
            content: eid,
            position: {
                my: 'right center',
                at: 'left center',
                target: $(this)
            },
            show: {
                event: event.type,
                ready: true
            },
            hide: {
                fixed: true
            }
        }, event); 

    });

但是,鼠标悬停事件的节点中没有显示工具提示。请帮助我。

4

2 回答 2

0

为 qtip 提供正确的坐标以与节点悬停交互。可以使用 cyPosition 完成希望这会有所帮助:

                cy.on('mousemove','node', function(event){
                var target = event.cyTarget;
                var sourceName = target.data("source");
                var targetName = target.data("target");

                var x=event.cyPosition.x;
                var y=event.cyPosition.y;                 


                        $("#box").qtip({
                            content: {
                                title:targetName,
                                text: sourceName
                            },
                            show: {
                                delay: 0,
                                event: false,
                                ready: true,
                                effect:false

                            },
                            position: {
                                my: 'bottom center',
                                at: 'top center',

                                target: [x+3, y+3],
                                adjust: {
                                    x: 7,
                                    y:7

                                }

                            },
                            hide: {
                                fixed: true,
                                event: false,
                                inactive: 2000

                            },


                            style: {
                                classes: 'ui-tooltip-shadow ui-tooltip-youtube',

                                tip:
                                {
                                    corner: true,
                                    width: 24,         // resize the caret
                                    height: 24         // resize the caret
                                }

                            }

                    }
                });
            })

您也没有指定事件目标。并且在处理画布时不要忘记使用 mousemove。

于 2014-05-04T17:47:04.507 回答
0

这是我今天找到的最佳解决方案。只需将此代码包含在您的 ready 函数中,除了 qtip 函数和 css 之外,还包括https://github.com/cytoscape/cytoscape.js-qtip,它会在单击节点或边缘时显示提示

    cy.elements().qtip({
                content: function(){ return 'Example qTip on ele ' + this.id() },
                position: {
                    my: 'top center',
                    at: 'bottom center'
                },
                style: {
                    classes: 'qtip-bootstrap',
                    tip: {
                        width: 16,
                        height: 8
                    }
                }
            });
            // call on core
            cy.qtip({
                content: 'Example qTip on core bg',
                position: {
                    my: 'top center',
                    at: 'bottom center'
                },
                show: {
                    cyBgOnly: true
                },
                style: {
                    classes: 'qtip-bootstrap',
                    tip: {
                        width: 16,
                        height: 8
                    }
                }
            });
于 2016-12-31T19:29:21.460 回答