显示和隐藏元素 [英] showing and hiding an element

查看:82
本文介绍了显示和隐藏元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在onmouseover和onmouseover上显示并隐藏div而另一个div元素。

i我在onmouseout上设置setTimeout持续时间以延迟div的隐藏大约两秒钟

问题是,当我鼠标悬停一个元素然后onmouseout它然后再次在超时前鼠标悬停该元素时,该元素仍然被隐藏

所以我把一个标志= 1当我的鼠标悬停在mouseout上元素和flag = 0并在调用隐藏函数时检查了标志的值


仍有问题

如果我重复鼠标悬停mouseout元素,在调用隐藏函数时,如果flag的值为0,它会在最后一次onmouseout的超时之前隐藏元素,甚至调用

不知道我是否明白了


这是我的代码

[HTML]< div id =" check"风格= QUOT;宽度:80px;高度:20像素;背景色:#666666;颜色:#FFFF00">悬停在这里< / div> [/ HTML]

[HTML]< div id =" mydiv"风格= QUOT;位置:绝对的;顶部:40像素;左:300像素;宽度:500像素;高度:400像素;背景色:#33CCFF;的z-index:1000; display:none >< / div> [/ HTML]

i am trying to show and hide a div when onmouseover and onmouseover another div element.
i am setting a setTimeout duration on onmouseout to delay the hiding of div for around two second
The problem is that when i mouseover an element and then onmouseout it and then back again mouseovers that element before the timeout, the element still gets hidden
so i put a flag=1 when i mouseover the element and flag=0 at mouseout and checked the value of the flag when calling the hiding function

still there was a problem
if i repeated mouseover and mouseout the element, at the time when the hiding function is called, if value of flag was 0, it hides the element before the timeout of last onmouseout even called
dont know if i made it any clear

here is my code
[HTML]<div id="checking" style="width:80px; height:20px; background-color:#666666; color:#FFFF00">hover here</div>[/HTML]
[HTML]<div id="mydiv" style="position:absolute; top:40px; left:300px; width:500px; height:400px; background-color:#33CCFF; z-index:1000; display:none " ></div>[/HTML]

展开 | 选择 | Wrap | 行号

推荐答案

我想我的工作正常但不太确定

我不知道是否可以通过任何其他方式实现


i更改我的代码以在标志中包含时间戳

并检查当前时间和时间戳的差异

i think i got it working but not too sure
I dont know if it can be achieved by any other way as well

i changed my code to include a timestamp in flag
and checked for the difference in current time and timestamp

展开 | 选择 | Wrap | Line数字



i认为我让它工作但不太确定

我不知道是否它可以通过任何其他方式实现


i更改我的代码以在标志中包含时间戳

并检查当前时间和时间戳的差异
i think i got it working but not too sure
I dont know if it can be achieved by any other way as well

i changed my code to include a timestamp in flag
and checked for the difference in current time and timestamp



我认为应该有效。比一个简单的标志更强大。

I think that should work. More robust than a simple flag.


是的我想在隐藏div元素之前等待几秒钟,如果用户将鼠标移离悬停元素有点放置延迟隐藏但是如果用户在隐藏div的超时之前返回悬停元素,div不应该被隐藏,并且当用户再次悬停在悬停元素之外时设置新的超时
yes i want to wait for a few seconds before hiding the div element if user has moved his mouse away from the hover element kinda putting a delayed hide but if the user gets back on the hover element before timeout of hiding of div, the div should not get hidden and a new timeout be set when the user hovers out of the hover element again


这篇关于显示和隐藏元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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