简体   繁体   English

Tooltipster插件在第一次尝试时不起作用

[英]Tooltipster plugin not working on first try

I am using the tooltipster plugin to have tooltip on hover. 我正在使用tooltipster插件在悬停时显示工具提示。

My code is posted in this jsfiddle , for some reason the tooltip wouldn't work on the first try, eg if you click Run in jsfiddle and move your pointer over the div that says 我的代码发布在此jsfiddle中 ,由于某种原因,该工具提示在第一次尝试时将无法正常工作,例如,如果您单击jsfiddle 运行” ,然后将指针移至显示以下内容的div上

Hover over me 悬停在我身上

Nothing happens but if you move your pointer away and then back on hover, it works. 什么都没有发生,但是如果您将指针移开然后又重新悬停,它将起作用。 Why doesn't it work on the first try? 为什么在第一次尝试时不起作用?

Thanks. 谢谢。

because you have declerad tooltip plugin on hover function. 因为您在悬浮功能上有declerad tooltip插件。 after declared it can run. 声明后可以运行。 so if you move this code to outside of hover function it will work. 因此,如果将此代码移到悬停功能之外,它将可以正常工作。

    $('.tooltip0').tooltipster({
                    content: $('<div id="mikrah">test hover div</div>'),
                    delay: 0,
                    theme: 'tooltipster-shadow',
                    contentAsHTML: true
   });

fiddle 小提琴

Try this: 尝试这个:

 $('.tooltip0').tooltipster({
    content: $('<div id="mikrah">test hover div</div>'),
    delay: 0,
    theme: 'tooltipster-shadow',
    contentAsHTML: true
});
$('.tooltip0').hover(
        function () {
            $('#students').attr('src', 'http://www.impexsoftdesign.com/images/stories/weird-and-funny-facts/lion.jpg');

        },
        function () {
            $('#students').attr('src', 'http://cdn.oxwordsblog.wpfuel.co.uk/wpcms/wp-content/uploads/Lion_iStock_XSmall-300x300.jpg?24a0bc');
        });

You were starting the tooltipster inside the inHandler in the hover , so, first time it initializes the tooltipster and only on the second hover it runs.. 您是在hoverinHandler内部启动工具提示的,因此,第一次它会初始化工具提示,并且仅在第二次hover时运行。

As stated in the hover() documentation, 如hover()文档所述,

.hover( handlerIn, handlerOut ) Where the handlerOut is a function to execute when the mouse pointer leaves the element. .hover(handlerIn,handlerOut)其中handlerOut是鼠标指针离开元素时要执行的函数。

Thus the second function, that shows the text, will fire after you leave the image with the mouse. 这样,第二个显示文本的功能将在您用鼠标离开图像后触发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM