如何防止jquery悬停效果在悬停时和悬停时激活

How to prevent jquery hover effect from activating on and off hover

本文关键字:悬停 激活 何防止 jquery      更新时间:2024-05-24

我使用的是blast.js,当你将鼠标移到元素上和移出元素时,我的悬停效果会触发。我希望它表现得像一个正常的悬停效果。我知道悬停效果通常设置为:

$('h1').hover(function(){
  //code here
}, function(){
  //code here
});

但我不确定在使用blast.js时,我会在第二个函数中放入什么,以防止它发生两次。

我有一把小提琴,但我不知道如何在小提琴上演奏。

演示

$(function() {
  $('h1').hover(function() {
    // Blasts the title
    var chars = $('h1').blast({
      delimiter: 'word'
    });
    // Animation character per character
    chars.each(function(i) {
      // Initialization of the position
      $(this).css({
        position: 'relative',
        left: 0
      }).delay(i * 45).animate({
        left: '50px'
      }, 300).delay(200).animate({
        left: 0
      }, 300);
    });
  });
});

当光标进入对象时,可以使用.mouseover(),当光标离开对象时,使用.mouseout()

这些是基于HTML事件的JQuery函数。还有其他活动,如mouseentermouseleave,您可以在W3Schools中找到它们。

您应该为函数添加参数:

$('h1').hover(function(e) { ... });

并调用体内:

e.preventDefault();