Welcome to WebDesignForums.net!
You're currently viewing WDF as a guest. By registering for a free account, you'll be able to participate with other members in our friendly community. Being a member allows you to ask questions and get answers for those troublesome web development tasks!

In addition, as a member you'll be able to post your websites up for review. Using our unique website review system you can gain some amazing feedback from some of the best web developers around. This is a completely free service to all registered members.

Ready to register yet? Registration is 100% free. Click Here To Join Now!

onMousePress and onMouseRelease for DIVs...

Discussion in 'Javascript, AJAX, and JSON' started by flipjargendy, Oct 14, 2007.

  1. Offline

    flipjargendy New Member

    Message Count:
    62
    Likes Received:
    0
    Trophy Points:
    0
    Is it possible to use onMousePress and onMouseRelease to make a div visible or hidden? For example onMousePress=visible and onMouseRelease=hidden.

    I haven't found much on this with Google... mostly just forum posts that aren't even dealing with what I'm looking for. This makes me wonder if what I'm going for is even possible.

    I probably didn't have to post code but I did it anyway in case anyone wanted to see what exactly I was doing... if I wasn't clear enough. All of the code works but the onMousePress and onMouseRelease.

    Code:
    <div style="position:absolute; width:85px; height:120px; margin-top:75px; margin-left:7px;" onmouseout="fullMouth.style.visibility='hidden'; ribblets.style.visibility='hidden'; onmouseover="fullMouth.style.visibility='visible'; dribblets.style.visibility='visible'" onmousepress="adict.style.visibility='visible'" onmouserelease="adict.style.visibility='hidden'"><img...blah /></div>


  2. Offline

    zonker New Member

    Message Count:
    6
    Likes Received:
    0
    Trophy Points:
    0
    You can do the rollover fairly easily with CSS.

    #div-id a {display: none;}

    Perhaps there is an "onclick" event that you can mark in here also.


  3. Offline

    Steax Cookie Monster

    Message Count:
    1,207
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Bandung, Indonesia
    If you want to go and pic up jQuery, which is a JS library, you can do something very simple. Like this.

    Markup:
    HTML:
    <div id="box">
      <a href=""id="divcloser">Click this to hide box</a>
    </div>
    
    And the JS:
    Code:
    $(function(){ // Ignore this opening bit for now
    
      $("#divcloser")  // CSS-like selector
         .click(function(){   // Define a click event - jQuery will manage it for you
           $("#box").hide("slow"); // Slowly show the box
        })
    
    }); // Ignore this closing bit for now
    
    Really doesn't get any simpler than that. If you want an open button, just replicate the script but replace the hide with show. Thats that.


  4. Offline

    flipjargendy New Member

    Message Count:
    62
    Likes Received:
    0
    Trophy Points:
    0
    Woah, I just tried a few scripts that are on the jQuery website and it is amazing! I'm going to give it a shot.

    Thanks for the link.


  5. Offline

    Steax Cookie Monster

    Message Count:
    1,207
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Bandung, Indonesia
    Glad you enjoy it. :) Feel free to ask if you have any questions... I usually answer most JS-related questions through jQuery code, anyway. It's always several times shorter than it'd be in plain JS.


Share This Page