- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
考虑一个简单的元素及其关联的 CSS:
<div id="content">Hover me !</div>
#content {
width: 100px;
height: 100px;
}
#content:hover {
transform: translateY(500px);
transition: transform 1s 500ms;
}
原则很简单:当元素悬停时,它必须向下移动。问题是,当鼠标不动时,:hover
状态会保持不变,即使该元素物理上不再位于鼠标下方(由于翻译) .状态似乎只有在鼠标移动后才会更新。
注意光标(指针)及其与元素的相对位置!
当一个 JavaScript 函数必须在 timeout
之后只有当鼠标在一个元素上时才必须执行时,这是一个真正的问题:
// The mouseleave event will not be called during the transition,
// unless the mouse move !
element.on('mouseenter', executeAfterTimeout);
element.on('mouseleave', cancelTimeout);
所以这是我的问题:
编辑: 为了给您一个上下文,这是我想具体做的事情:使用 JavaScript,当鼠标位于某个元素上时(并且当鼠标离开时隐藏它)。但是当用户点击它时,相同的元素可以被 transform
编辑。如果用户只是单击而不移动鼠标,工具提示将保持显示状态,这是一个真正的问题。如何检测元素是否消失?
最佳答案
The principle is straightforward: while the element is hovered, it must go down. The problem is, when the mouse doesn't move, that the :hover state is maintained even if the element is not physically below the mouse anymore (due to the translation). The state seems to be updated only after an mouse move.
So here are my questions:
- Is this behaviour normal (compliant with the norms)?
是的。这种行为是正常的。虽然标准中没有逐字规定,但在这里详细提到: http://www.w3.org/TR/2013/WD-DOM-Level-3-Events-20131105
以这个 fiddle 为引用:http://jsfiddle.net/Blackhole/h7tb9/3/
上面的 div
直接绑定(bind)了鼠标事件。下方的 div
将鼠标事件绑定(bind)到其父级。拿起下面的那个。在一侧缓慢移动鼠标并观察控制台,看看会发生什么。
mouseover
和 mouseenter
会快速连续触发(悬停)。div
进行了翻译。div
内。 mousemove
触发,内部 div
仍被翻译。mouseout
和 mouseleave
快速连续触发,内部 div
转换回其原始位置。这在此处描述: http://www.w3.org/TR/2013/WD-DOM-Level-3-Events-20131105/#events-mouseevents 在 鼠标事件顺序 部分下。
上面的第 3 步很重要。因为你什么都不做,所以没有事件被触发,因此什么也没有发生。如果内部 div
在此步骤中弹回其原始位置,则意味着在没有任何事件的情况下发生了激活!
这符合event作为本节文档的定义:http://www.w3.org/TR/2013/WD-DOM-Level-3-Events-20131105/#glossary-event说:
An event is the representation of some occurrence (such as a mouse click on the presentation of an element, the removal of child node from an element, or any number of other possibilities) which is associated with its event target. Each event is an instantiation of one specific event type.
现在看看这里的文档: http://www.w3.org/TR/2013/WD-DOM-Level-3-Events-20131105/#event-flow ,就在 3.2 节 开始之前,它说:
After an event completes all the phases of its propagation path, its Event.currentTarget must be set to null and the Event.eventPhase must be set to 0 (NONE). All other attributes of the Event (or interface derived from Event) are unchanged (including the Event.target attribute, which must continue to reference the event target).
最后一行(括号内)很重要。即使在事件完成后,event.target 仍会继续引用事件目标。
现在选择 fiddle 中上方的 div
作为引用。在 mouseenter
上,div
本身被翻译。 它是否从鼠标指针下方移开并不重要。 event.target 仍然引用它,如果没有其他鼠标事件发生,则什么也不会发生,它会保持翻译状态。当您移动鼠标(向内或向外的任意位置)时,激活发生在 event.target(仍然是这个 div
)并且现在用户代理发现鼠标指针不再位于元素上 并立即触发 mouseout
和 mouseleave
事件(当然是在触发 mousemove
之后) 导致 div
转换回来。
2.What are the solutions to avoid this problem?
Edit : To give you a context, here is what I want to do concretely: with JavaScript, I display a tooltip when the mouse is on an element (and hide it when the mouse leaves it). But the same element can be transform-ed when the user click on it. If the user simply clicks without moving the mouse, the tooltip will remain displayed, which is a real problem. How can I detect that the element is gone?
如果您查看此 fiddle 中较低的 div
中的实现:http://jsfiddle.net/abhitalks/h7tb9/2/ ;与上部 div 相比,鼠标悬停时没有颤动/抖动。这是因为事件不是在 div
本身,而是在父级上处理。
因此,这可能是您的用例的一种解决方案。
查看此演示:http://jsfiddle.net/Blackhole/nR8t9/9/
这解决了您的编辑问题。工具提示显示在 mouseover
上。工具提示在 mouseleave
上隐藏。当您单击
时,可以转换相同的元素。如果您只是简单地单击
而不移动鼠标,则工具提示会隐藏。
在这里,如果您单击
,该元素将被翻译,然后不会发生进一步的悬停
操作。工具提示本身是使用 :before
伪元素实现的。这将工具提示和您要在 click
后更改的元素分开。您仍然处理元素本身的事件。不需要超时,因为它由 css 本身处理。如果您mouseout
,工具提示将在延迟后隐藏。
希望对您有所帮助。
关于javascript - 即使元素已经消失,悬停状态也会在过渡期间保持不变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23445468/
我有 2 个表 t1,其中存储价格和项目类型以及一个 ENUM 值和 t2,其中存储销售数量。我有一个计算总销售额(价格 * 数量)的查询,但我需要计算两个结果数字之间的差值。 两个数之差的计算公式应
我在使用 zsh 运行 Big Sur 11.2 的 Mac 上更改运行的 java 版本时遇到问题。我想将 Java 1.8 设置为默认设置,因此我使用以下命令设置 JAVA_HOME: $ uns
在下面的代码中,当我改变选择时,会有一个alert。我试图使该功能类似于当我单击 option 时它会显示 alert。 $(document).ready(function() { $("#x"
好吧,我正在制作一个简单的 react 游戏,我的代码如下。现在,当调用 startGame() 时,如果我注释掉 while 循环,一切都会发生,但是当我使用 thread.sleep(1000)
我目前正在尝试将 .plist 文件中的 CFBundleURLTypes 的值更改为新值,但似乎没有任何效果,并且如果我调用,旧值仍然存在 NSLog(@"%@", [[NSBundle mainB
我正在尝试使用 Jsoup 中的解析函数来解析 html 字符串。 我尝试阅读了很多相关的帖子以及API,但仍然没有找到答案。 String html = ""others"; Docume
我正在尝试为水平列表项关闭设置动画alpha 动画有效,layoutparam 值也随时间减少但出于某种原因,这并没有改变列表项的实际高度。 @Override protected void appl
双管道等于: MY_CONST ||= 42 运算符定义? MY_CONST = 42 unless defined? MY_CONST 为什么第二种方式更为普遍?第一个有什么缺点吗? 最佳答案 在一
我希望我的站点地址栏在访问子页面时不要更改其地址,它应该显示我的 index.html ,即使我进入 tosub 页面。 就像我打开 www.xyz.com我导航到它仍应显示的任何页面 www.xyz
我试图通过将购物车存储在数据库的表中来创建购物车,而不是使用内置的 CI 购物车类。我使用 sessionID 来识别一个访问者和另一个访问者。但是我发现sessionID在一段时间内一直在变化,连访
我面临一个奇怪的问题。一旦更改了.java文件-看来测试仍在使用该文件的早期版本(.class)。 从我的 Angular 来看,应该从.build文件夹中删除该类,并从新版本的.java文件重新编译
下面的R代码显示了一个关于向量组合的例子,之后,向量“c”的属性变成了字符。如何让它仍然保持属性为数字? a='aa';b='bb';c=c(1,2,3,4,5) dd=data.table(cbin
我一直在使用 Kinect 和语音识别,我注意到我无法让 AudioLevel 成员从我的 SpeechRecognitionEngine 对象中更改。 我成功地让命令被识别,所以我知道 kinect
大家好,我已经实现了通知功能。我对通知 ID 有疑问。 这是我的代码: protected void ShowNotification(String title, String text){ Noti
所以我第一次正确设置了 UIView 图层的阴影(它显示得非常好)但是当我尝试更改颜色时(没有别的,只是 layer.shadowColor)它不会在 View 中更新。它仍然显示原始颜色。我已经尝试
使用 java 我想在一个程序中生成一些随机值,然后在每次执行第二个程序时在其他程序中使用这些值。 这样做的目的是生成一次随机值,然后在以后每次运行程序时保持并保持它们不变。有可能吗?谢谢 最佳答案
我有几个组件,所有组件都继承了 JCheckBox 而没有覆盖它的任何内容,存储在一个 vector 中,然后遍历该 vector 并将每个组件添加到一个对话框中 CreateLists(); //
我有一个 UITabBarController。现在我想在其上方添加一个 View ,并在用户切换到另一个选项卡时使 View 保持不变。我尝试创建一个 UIViewController,并将 UIT
我正在使用 curses 来打印一个非常漂亮的控制台 UI,我需要它依赖于终端大小。为此,我阅读了 here ,我可以使用 shutil.get_terminal_size .所以我正在做这段代码:
我有一个jsfiddle here . fiddle 中有许多标记文本框。在文本框中输入一个数字,然后继续单击“添加问题”按钮。您将看到剩余的总分等于 10,但它不会改变。剩余分数的数量应该通过减去附
我是一名优秀的程序员,十分优秀!