Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When <code>visibility: hidden</code> is set, no mouse events are sent to the element. </p> <p>What you were seeing is the <code>mouseout</code> event firing as the element went hidden which then caused the code to set it visible again which then triggered the <code>mouseover</code> event as soon as the mouse moved - and so on. </p> <p>Some additional information here: <a href="https://stackoverflow.com/questions/272360/does-opacity0-have-exactly-the-same-effect-as-visibilityhidden">Does opacity:0 have exactly the same effect as visibility:hidden</a></p> <p>Use <code>opacity: 0</code> instead.</p> <p><a href="http://jsfiddle.net/davidcl64/uFLPg/2/" rel="nofollow noreferrer">Fiddle</a></p> <pre><code>window.onload = function(){ var tag = document.getElementById('tag'); tag.style.opacity = 0; tag.onmouseover = function () { tag.style.opacity = 1; } tag.onmouseout = function () { tag.style.opacity = 0; } } </code></pre> <hr> <p>If you are concerned about older browser support for opacity, you can still use <code>visibility: hidden;</code> by wrapping the <code>tag</code> div in a <code>div</code> with its background set to <code>transparent</code>. </p> <p>Attach the mouseover/mouseout handlers to the wrapping div and change the visibility of the child. This avoids the repeated mouseover/mouseout events as the wrapper will always receive mouse events.</p> <p><a href="http://jsfiddle.net/davidcl64/uFLPg/4/" rel="nofollow noreferrer">Demo 2:</a></p> <p>HTML:</p> <pre><code>&lt;div style='position:relative'&gt; &lt;div id='tag' style='position : absolute; top: 20px; left: 20px; width: 50px; height: 50px; z-index: 10; background: transparent;'&gt; &lt;div id='tagInner' style=' border: 1px solid red; position : absolute; top: 0; left: 0; right: 0; bottom: 0;'&gt; &lt;/div&gt; &lt;/div&gt; &lt;img src='http://www.hihowareyou.com/store/images/products/tn_HiVinylFrontmed.jpg' id='wow'&gt; &lt;/div&gt; </code></pre> <p>Code:</p> <pre><code>var tag = document.getElementById('tag'); var tagInner = document.getElementById('tagInner'); tagInner.style.visibility = 'hidden'; tag.onmouseover = function () { tagInner.style.visibility = 'visible'; } tag.onmouseout = function () { tagInner.style.visibility = 'hidden'; } </code></pre> <hr> <p>There is also an interesting writeup on CSSTricks about <a href="http://css-tricks.com/css-transparency-settings-for-all-broswers/" rel="nofollow noreferrer">CSS Transparency Settings for All Browsers</a>. I haven't tried that approach myself with older browsers, but it may work for you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload