English 中文(简体)
在改变某一要素的可见度时,不要求活动
原标题:Events are not called when changing visibility of an element

我有一页,需要定期间隔,以吸引四分五裂的可见度。 问题是,与父母一方有关的点击事件往往没有点。 如果我停止了眼光,或者如果我放慢了眼光(例如300米而不是100米),那么点击事件通常会发生。

I have created a short example illustrating this issue. You can test it here: http://threeds.me/0xC0DE/

从理论上来说,浮出蓝/红广场应焚烧点击事件。 当没有估计(此处的过失行为)时,点击蓝广场将总是向浮标事件开火。 如果你点击游戏/播火,红广场的可见度将开始逐个点。 当点燃时,每当你点击广场时,就不要打上点击。

I would suspect that changing the visibility is somehow messing up with the DOM which as a result stop events for some milliseconds. I also tried to toggle the css visibility property to minimize the impact on the page but it has the same result.

But it s not only events. If I encapsulate the whole container in an tag, clicking the element will not be always taking into account by the browser. So it s like that changing the visibility of a child element will make a parent blind for (quite) some time which I find really strange.

这个问题与Motherine、Husain和Ampact(所有 on,都无法检测到ie)是一致的,因此,这意味着我不会得到一些东西。 因此,即使我没有找到解决办法,我也想知道问题是什么。

在此请您立即参考。

<!DOCTYPE html>
<html>
<head><title>Wiggle problem</title>
<style>
#dback {
    width: 200px;
    height: 200px;
    background-color: red;
}
#dfront {
    width: 200px;
    height: 200px;
    background-color: blue;
}
</style>

<script type="text/javascript">
var run = false;
function playpause() {
    if ( run ) {
        run = false;
    } else {
        run = true;
        update();
    }
}

function update() {
    if ( run==false ) {
        return;
    }

    var el = document.getElementById( dfront );
    if ( el.style.display !=  none  ) {
        el.style.display =  none ;
    }
    else {
        el.style.display =   ;
    }

    setTimeout("update();", 100);
}
</script>

</head>

<body>
<a href="#" onclick="playpause();">play/pause</a>
<div id="container" onclick="d=new Date();t=d.getTime();document.getElementById( info ).innerText= click  +t;">
    <div id="dback">
        <div id="dfront"></div>
    </div>
</div>
<span id="info"></span>
</body>
</html>
最佳回答
问题回答

Acctually, when "dfront" is visible, its hovering over "container", and when you make a click, event goes to "dfront". but there is no onclick event, for "dfront" element. Onclick event of "container" is not propagating on child elements - its normal, you can workaround it by using jquery it has "event propagation" option for events. Or just set onclick event for "dfront".

Also you can create transparent layer over "container" and "dfront" and bind event to it. Or, make onmouseclick event on window object, which will find out, if mouse position is over "dfront" by checking their coordinates and if true then event handler will be fired.





相关问题
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.