PDA

View Full Version : Show Hide text on image rollover



steve555
09-28-2012, 09:21 PM
Hi


I'm using the following javascript



<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js"></script>
<script>
$(document).ready(function() {
$('.nav-toggle').mouseover(function(){
//get collapse content selector
var collapse_content_selector = $(this).attr('href');

//make the collapse content to be shown or hide
var toggle_switch = $(this);
$(collapse_content_selector).toggle(function(){
if($(this).css('display')=='none'){

}
});
});

});
</script>


to expand a div and show some text on the rollover of an image.



<a href="#collapse1" class="nav-toggle"><img src="images/image_name.jpg" width="298" height="59" alt="image">

<div id="collapse1" style="display:none">my text that is revealed is this section.....</div>


It works well, but using the above code the revealed text above stays in place until you mouseover the image again upon which it is hidden.

I would like to change this so that you still mouseover the image to reveal the text, but as soon as you mouseout it is hidden.

eg. you don't have to mouseover it again to close it.


I'm sure all I need is a simple tweak to the code above, so if you can help asap it would be appreciated!

bernie1227
09-29-2012, 12:40 AM
You could try something like this.


<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js"></script>
<script>
$(document).ready(function() {
$('.nav-toggle').mouseover(function(){
//get collapse content selector
var collapse_content_selector = $(this).attr('href');

//make the collapse content to be shown or hide
var toggle_switch = $(this);
$(collapse_content_selector).toggle(function(){
if($(this).css('display')=='none'){

}
});
});
$('.nav-toggle').mouseout(function(){
//get collapse content selector
var collapse_content_selector = $(this).attr('href');

//make the collapse content to be shown or hide
var toggle_switch = $(this);
$(collapse_content_selector).toggle(function(){
if($(this).css('display')=='none'){

}
});
});
});
</script>