-1

我正在尝试将 cytoscape 与tippy 一起使用,但它没有显示任何工具提示。它会抛出 ele.popperRef 不是函数的错误。

这是 stackblitz 链接:https ://stackblitz.com/edit/dagre-tippy?file=src%2Fapp%2Fapp.component.ts

我已经添加了所有需要的包,包括 popper.js、tippy.js 但它仍然不起作用

4

1 回答 1

2

检查这个https://stackblitz.com/edit/dagre-tippy-wgg8zz

您不仅仅是正确地导入库并注册 cytoscape.js 扩展。

你应该注册 popper 扩展cytoscape.use(popper);

您可以将tippy.js 与类似的功能一起使用

function makePopperWithTippy(node) {
  let ref = node.popperRef(); // used only for positioning

  // A dummy element must be passed as tippy only accepts dom element(s) as the target
  // https://atomiks.github.io/tippyjs/v6/constructor/#target-types
  let dummyDomEle = document.createElement("div");

  let tip = tippy(dummyDomEle, {
    // tippy props:
    getReferenceClientRect: ref.getBoundingClientRect, // https://atomiks.github.io/tippyjs/v6/all-props/#getreferenceclientrect
    trigger: "manual", // mandatory, we cause the tippy to show programmatically.

    // your own custom props
    // content prop can be used when the target is a single element https://atomiks.github.io/tippyjs/v6/constructor/#prop
    content: () => {
      let content = document.createElement("div");

      content.innerHTML = "Tippy content";

      return content;
    }
  });

  tip.show();
}

另外,请注意您不必使用tipp.js。实际上只需 popper.js 就足够了。

function makePopper(ele) {
  // create a basic popper on the first node
  let popper1 = ele.popper({
    content: () => {
      let div = document.createElement("div");

      div.innerHTML = "Popper content";

      document.body.appendChild(div);

      return div;
    },
    popper: {} // my popper options here
  });
}

您可以在下面应用这些功能并查看工具提示。在此之后,基于事件的显示打开和关闭很简单。

cy.elements().forEach(function(ele) {
  makePopperWithTippy(ele);
  // makePopper(ele);
});
于 2021-03-26T08:55:08.383 回答