jQuery如何杀死已创建的Div? [英] jQuery How to kill a Created Div?

查看:58
本文介绍了jQuery如何杀死已创建的Div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我拥有的是产品(div)列表,将它们悬停在上方时,会创建一个重复的div并将其放置在原始div上(偏移一点并使用css重新设置样式).这个新的div更大,并提供了列表视图中显示的更多信息.

What I have at the moment is a list of products (divs) that, when hovered over, a duplicate div is created and positioned over the original div (offset a bit and restyled using css). This new div is larger and offers more information that was being shown in the list view.

当我将鼠标悬停在新的div上时,它是.remove()的,但是我发现它不会立即执行此操作,并且如果我足够快地移动鼠标,则会触发悬停事件,但是mouseleave事件是不会(因此,新的div仅显示在屏幕上).

When I hover off the new div it is .remove()'d, however I have found that it does not do this immediately, and if I move my mouse fast enough the hover event is fired, but the mouseleave event is not (as such the new div is just left on screen).

此刻我有什么要检测何时删除新的div:

What I have at the moment to detect when to remove the new div:

jQuery('.newDiv').mouseleave(function(){
  jQuery(this).remove();
});

我如何让我的新div检查鼠标是否处于打开/关闭状态,以便我可以正确地将其杀死?

How do I get my new div to check that the mouse is on/off it so that I can kill it correctly?

推荐答案

您是否考虑过使用CSS对其进行修补?

Have you thought about using CSS to patch it?

.newDiv{
  display:none;
}
  .newDiv:hover{
    display:block;
  } 

这样,悬停将始终隐藏div.可能是渲染代理比JS引擎更快,从而节省了您的瞬时故障.

That way, unhover will hide the div anyway. Might be that the rendering agent is quicker than the JS engine, saving you that momentary glitch.

这篇关于jQuery如何杀死已创建的Div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆