Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>My demo will fade-in the <strong>square</strong> upon hovering the <strong>circle</strong>. From there, when you hover over the <strong>square</strong>, it will stay opaque. After you move off the <strong>circle</strong> or <strong>square</strong>, the <strong>square</strong> will fade-out.</p> <p>The trick to getting this to work is setting 2 different transitions for the <code>opacity</code>, <code>height</code>, and <code>width</code> properties of the <strong>square</strong>, one for <strong>hover ON</strong> and one for <strong>hover OFF</strong>, as well as adding a <code>delay</code> attribute to the transition. The reason for transitioning <code>height</code> and <code>width</code> is that it will prevent you from being able to hover over the <strong>square</strong> without first hovering over the <strong>circle</strong>.</p> <p>Here are the default settings of the <strong>square</strong>: <code>opacity: 0</code>, <code>height: 0</code>, and <code>width: 0</code>. </p> <p>For the <strong>hover ON</strong> transition, you want <code>opacity</code> to fade-in over 1 second, but to be able to see that, the <code>height</code> and <code>width</code> values need to be 40px prior to the fade-in transition. To make that happen, you need to set a delay of 0 seconds on the <code>height</code> and <code>width</code> transitions. This way, the <strong>square</strong> is immediately at its max dimensions, which allows the fade-in transition to be seen.</p> <p>The <strong>hover OFF</strong> transition will revert back to the default settings. What you want to have happen is for the <code>opacity</code> to ease-out over 1 second while at the same time keeping the values of <code>height</code> and <code>width</code> at 40px. Otherwise, <code>height</code> and <code>width</code> would instantly revert back 0 and you would not be able to see the fade-out transition. To make that happen you need to set a delay of 1 second on the <code>height</code> and <code>width</code> transitions. In doing that, the <code>opacity</code> eases out over 1 second and because of the 1 second delay on <code>height</code> and <code>width</code>, at that point, <code>height</code> and <code>width</code> will revert back 0.</p> <h2><a href="http://jsfiddle.net/twa7F/" rel="nofollow"><strong><em>See the jsFiddle demo</em></strong></a></h2> <p><br /></p> <h2>HTML</h2> <pre><code>&lt;div id="gravatar"&gt; &lt;div id="circle"&gt;&lt;/div&gt; &lt;div id="square"&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p><br /></p> <h2>CSS</h2> <pre><code>#gravatar { float: left; } #circle { background-color: blue; float: left; height: 40px; width: 40px; border-radius: 20px; } #square { background-color: red; float: left; margin-left: 10px; height: 0; width: 0; opacity: 0; /* hover OFF */ -webkit-transition: opacity 1s 0 ease-in-out, height 0s 1s ease, width 0s 1s ease; -moz-transition: opacity 1s 0 ease-in-out, height 0s 1s ease, width 0s 1s ease; -o-transition: opacity 1s 0 ease-in-out, height 0s 1s ease, width 0s 1s ease; -ms-transition: opacity 1s 0 ease-in-out, height 0s 1s ease, width 0s 1s ease; transition: opacity 1s 0 ease-in-out, height 0s 1s ease, width 0s 1s ease; } #square:hover, #circle:hover + #square { height: 40px; width: 40px; opacity: 1; /* hover ON */ -webkit-transition: opacity 1s 0 ease-in-out, height 0 0 ease, width 0 0 ease; -moz-transition: opacity 1s 0 ease-in-out, height 0 0 ease, width 0 0 ease; -o-transition: opacity 1s 0 ease-in-out, height 0 0 ease, width 0 0 ease; -ms-transition: opacity 1s 0 ease-in-out, height 0 0 ease, width 0 0 ease; transition: opacity 1s 0 ease-in-out, height 0 0 ease, width 0 0 ease; } </code></pre> <p><br /></p> <hr> <h2>EDIT</h2> <p>The OP left a comment stating that adding contents to the <strong>square</strong> prevents the transitions from working correctly. I corrected it by adding <code>overflow: hidden</code> to the <strong>square</strong>.</p> <p><em>I also added other styles to the CSS to account for the anchors the OP added.</em></p> <h2><a href="http://jsfiddle.net/8jqvN/" rel="nofollow"><strong><em>See the jsFiddle demo</em></strong></a></h2> <p><br /></p> <h2>HTML</h2> <pre><code>&lt;div id="gravatar"&gt; &lt;div id="circle"&gt;&lt;/div&gt; &lt;div id="square"&gt; &lt;a href="http://techyoucation.com/?page_id=156"&gt;Profile Details&lt;/a&gt; &lt;a href="http://techyoucation.com/?page_id=59"&gt;Account Details&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p><br /></p> <h2>CSS</h2> <pre><code>#gravatar { float: left; } #circle { background-color: blue; float: left; height: 40px; width: 40px; border-radius: 20px; } #square { background-color: #2D3538; float:left; overflow: hidden; margin-left: 10px; height: 0; width: 0; opacity: 0; /* hover OFF */ -webkit-transition: opacity 1s 0 ease-in-out, height 0 1s ease, width 0 1s ease; -moz-transition: opacity 1s 0 ease-in-out, height 0 1s ease, width 0 1s ease; -o-transition: opacity 1s 0 ease-in-out, height 0 1s ease, width 0 1s ease; -ms-transition: opacity 1s 0 ease-in-out, height 0 1s ease, width 0 1s ease; transition: opacity 1s 0 ease-in-out, height 0 1s ease, width 0 1s ease; } #square &gt; a { display: block; font: 15px Verdana; color: #FFF; text-decoration: none; height: 15px; line-height: 15px; margin: 10px; } #square &gt; a:last-child { margin-top: 0; } #square &gt; a:hover { text-decoration: underline; } #square:hover, #circle:hover + #square { height: 60px; width: 135px; opacity: 1; /* hover ON */ -webkit-transition: opacity 1s 0 ease-in-out, height 0 0 ease, width 0 0 ease; -moz-transition: opacity 1s 0 ease-in-out, height 0 0 ease, width 0 0 ease; -o-transition: opacity 1s 0 ease-in-out, height 0 0 ease, width 0 0 ease; -ms-transition: opacity 1s 0 ease-in-out, height 0 0 ease, width 0 0 ease; transition: opacity 1s 0 ease-in-out, height 0 0 ease, width 0 0 ease; } </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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