jQuery setTimeout

前端 未结 6 2348
刺人心
刺人心 2021-02-15 11:32

I\'d like to add a timeout to this tooltip code so it only displays if the mouse hovers over it after a while rather than immediately... I tried adding the setTimeout()

6条回答
  •  别跟我提以往
    2021-02-15 12:37

    As you're using animation, you can use .delay() to defer the appearance of your tooltip:

    $(mcTooltip).text(mcHoverText).delay(1000).show('fast');
    

    In your mouseout function, use .stop to cancel any existing delays or animations, and then hide the tooltip:

    $(mcTooltip).stop(true).hide('fast');
    

提交回复
热议问题