jquery - Jquery 中的鼠标悬停与悬停

标签 jquery html

这个问题是信息相关的。我是 jquery 的新手。我在 HTML 和 CSS 方面非常有经验。

Jquery 中的悬停和鼠标悬停有什么区别。 将鼠标悬停在元素上时,它们不是都被激活了吗。

最佳答案

mouseover():为该元素的子元素触发事件。

hover():悬停实际上可以与 mouseentermouseleave 配合使用,而不会触发子项。

要实现悬停效果,我们需要mouseovermouseout事件

$("element").mousover(function(){ 
    //do something over
}).mouseout(function() { 
    //do something out
});

而在 hover() 中它只是一个回调。

$("element").hover(
  function () {
    //do something enter
  }, 
  function () {
    //do something exit
  }
);

From David Jones's experience:

In the project I was working on I setup a container div to use mouseover and mouseout which added some html tabs to the container. This seemed perfectly fine but I discovered that using mouseover/mouseout meant the added html kept disappearing when I tried to interact with it along with the other jquery I had in place that was conflicting with it.

In the end my particular solution required me to use mouseenter and mouseleave with the live function rather than using hover because I was working with generated html.

关于jquery - Jquery 中的鼠标悬停与悬停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18060569/

相关文章:

html - 如何使用 CSS 使我的文本动画按特定顺序运行并在页面中间开始?

html - 将一个 div 水平对齐到左侧,一个标题对齐到中心,一个 div 水平对齐到右侧

javascript - 循环上课

jQuery:添加类

javascript - jQuery 轮播 slider 停留在灯箱图像的前面

javascript - 未捕获错误 : Syntax error, jQuery 升级后无法识别的表达式

javascript - 在日历中显示表格

html - 我怎样才能把一个标签放在一个盒子的中间

javascript - 单击缩略图时图像未显示在模式中

javascript - 我需要在 javascript/服务器端和客户端冲突中使用 php 变量