Results 1 to 2 of 2

Thread: Show Hide text on image rollover

  1. #1
    Join Date
    Sep 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Show Hide text on image rollover

    Hi


    I'm using the following javascript


    Code:
    <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.


    Code:
    <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!
    Last edited by keyboard; 09-29-2012 at 06:53 AM. Reason: Format: Code Tags

  2. #2
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    You could try something like this.
    Code:
    <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>
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

Similar Threads

  1. Mouse Over Text Hide/Show Image JS Needed
    By softgeometry in forum Looking for such a script or service
    Replies: 6
    Last Post: 10-03-2009, 10:24 AM
  2. show/hide text on a page
    By Hitta in forum CSS
    Replies: 15
    Last Post: 06-19-2007, 01:50 AM
  3. Replies: 2
    Last Post: 11-21-2006, 03:34 AM
  4. Show/Hide text with CSS over an image?
    By magic5227 in forum CSS
    Replies: 3
    Last Post: 10-04-2006, 12:56 AM
  5. Show Hide DIV using Image
    By jpaulraj in forum JavaScript
    Replies: 4
    Last Post: 07-15-2006, 02:46 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •