[英]Tippy.js - Unable to hide a tooltip using the tippy.js documentation function
I'm using tippy.js for tooltips on a website, but it comes to a point when I have to hide them manually with a function (on mobile). 我在网站上使用tippy.js作为工具提示,但是到了必须使用功能手动隐藏它们的时候(在移动设备上)。 However I'm unable to hide it using the built in function hide()
但是我无法使用内置函数hide()
隐藏它
Am I doing something wrong or is the library bugged? 我做错什么了吗?还是库出错了?
Here's the documentation showing the hide() function. 这是显示hide()函数的文档 。 And here's a snippet of my problem. 这是我的问题的摘要。
var instance = new Tippy('button') var i = 0; $(document).on('keyup', function() { $('.clickcount').html(i); i++; var popper = instance.getPopperElement(document.querySelector('.tippy-popper')); instance.hide(popper) })
button { margin: 20px; }
<link href="https://atomiks.github.io/tippyjs/tippy/tippy.css" rel="stylesheet" /> <script src="https://atomiks.github.io/tippyjs/tippy/tippy.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button title="text">Button with Tippy</button> <div class="clickcount">Focus the document, then hover the button and press any key to hide it.</div>
Any and all help appreciated! 任何和所有帮助表示赞赏!
From the documentation : 从文档中 :
Find the element's popper reference by calling the method
getPopperElement
and passing in the element directly: 通过调用方法getPopperElement
并直接传递元素来查找元素的popper引用:
You need to pass your element to getPopperElement
, not the popup. 您需要将元素传递给getPopperElement
,而不是弹出窗口。
var instance = new Tippy('button') var i = 0; $(document).on('keyup', function() { $('.clickcount').html(i); i++; var popper = instance.getPopperElement(document.querySelector('button')); instance.hide(popper) })
button { margin: 20px; }
<link href="https://atomiks.github.io/tippyjs/tippy/tippy.css" rel="stylesheet" /> <script src="https://atomiks.github.io/tippyjs/tippy/tippy.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button title="text">Button with Tippy</button> <div class="clickcount">Focus the document, then hover the button and press any key to hide it.</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.