English 中文(简体)
a)mouseleave
原标题:check for ( div )mouseenter on ( a )mouseleave

my problem is following: I got a trigger(a) and a popup(div). The div doesn t lie nested inside the anchor.

  • When I hover over a, I want the div to show up.
  • When I go from a to the div, I want it to stay visible.
  • When I leave the div, I want it to close.
  • When I hover over a and leave without entering the div, I want the div to close.

I got most of that figured out, but now I m struggeling with requierement no. 2. When checking for mouseleave on a, I check if there is a mouseenter on the div. If it is, I want to abort the mouseleave. If not, I want to close the div.

我做了什么错误? 这样做是否正确?

这里标示:

<a href="#" class="popup_toggle" style= display:block;width:50px;height:50px;border:1px solid red;position:relative; >Toggle</a>
<div class="popup_div" style= position:absolute;top:50px;left:0px;border:1px solid blue;display:none; >Popup</div>

Here s the jQuery:

$( .popup_toggle ).mouseenter(function() {
        var element = $(this).next( .popup_div );
        $.data(this,  timer , setTimeout(function() {
            element.show(100);
        }, 500));
    });

    $( .popup_toggle ).mouseleave(function() {
        clearTimeout($.data(this,  timer ));
            if($( .popup_div ).mouseenter==true)
            {
                return false;
            }
            else
            {
                $( .popup_div ).hide(100)
            };
    });
最佳回答

你试图做的是很简单。 在进入触发点时,确定小组(无论大小),在使用数据(数据)时不相互提及,如果相关目标(从小组的角度来看)或小组(从触发小组的角度来看),则对事件处理器进行检查。 我一心一想一想。 查阅青少年日志,看看看这一工程是如何运作的:

问题回答

这很可能不会奏效。 我建议你增加<条码>。 背书:<div> 元件,并设定一个全球变量,说明如何处理其事件,即“如果全球变数真,就不掩饰烟雾,否则就隐藏着烟雾”或类似的东西。

The other approach would be to check whether the mouse is inside the popup when the mouseleave callback tries to hide the popup. That might be much more work than it is worth though.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签