Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Add a container for my-div</p> <pre><code>&lt;div class="rel-wrap"&gt; &lt;img src="http://placekitten.com/g/920/300" width="920" height="300" class="my-img"&gt; &lt;div class="my-div"&gt; Redbox &lt;/div&gt; &lt;/div&gt; </code></pre> <p>Set position as relative for container</p> <pre><code>.rel-wrap { position:relative; width:920px; height:300px; border: solid 1px #ccc; } </code></pre> <p>and apply top and left to my-div</p> <pre><code>.my-div{ position: absolute; background: red; width: 920px; height: 300px; left: -940px; /*a little far left than the required block*/ top: 0px; } </code></pre> <p>I've added a delay of 1 second in the animation(before callback). </p> <pre><code>$(document).ready(function(e) { $('.my-img').hover(function(){ $('.my-div').animate({left: '0px'}, 1000) }, function(){ $('.my-div').delay( 1000).animate({left: '-940px'}, 1000) }); }); </code></pre> <p>Code: <a href="http://jsfiddle.net/babumxx/Y4wC4/8/" rel="nofollow">http://jsfiddle.net/babumxx/Y4wC4/8/</a></p> <p>Preview: fiddle.jshell.net/babumxx/Y4wC4/8/show/</p> <p>You can also do it in two parts. Show on <em>mouseenter</em> and hide on <em>mouseout</em> </p> <pre><code>$(document).ready(function(e) { $('.my-img').mouseenter(function(){ $('.my-div').animate({left: '0px'}, 1000); }); $('.my-img').mouseout(function(){ $('.my-div').delay( 1000).animate({left: '-940px'}, 1000); }); }); </code></pre> <p>Fiddle here : jsfiddle.net/babumxx/Y4wC4/9/</p> <p>Since you want to keep the redblock, you can apply mouse out on the container, and this will solve this issue. - Fiddle: <a href="http://jsfiddle.net/babumxx/Y4wC4/10/" rel="nofollow">http://jsfiddle.net/babumxx/Y4wC4/10/</a></p> <pre><code>$(document).ready(function(e) { $('.my-img').mouseenter(function(){ $('.my-div').animate({left: '0px'}, 1000); }); //Trigger hide, when mouse leaves rel-wrap $('.rel-wrap').mouseleave(function(){ $('.my-div').delay( 1000).animate({left: '-940px'}, 1000); }); }); </code></pre> <p>Hope this helps.</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. 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