简体   繁体   中英

show hidden div over current div and next hide

<div id="home">
    <div id="logo">  </div>

        <div id="foot"> <div class="button"> CLICK ME</div>  
            <div class="button two"> CLICK ME</div> </div>
</div>

<div id="show">
    TEST TEST TEST TEST
</div>

$('.button').click(function(){
    $('#show').show();
})

#home {
 width: 400px;
 height: 400px;
 background-color: #ccffff;   
}

#logo {
   width: 100%;
   height: 300px;
    background-color: #0099ff;
}

#foot {
   width: 100%;
   height: 100px;
    background-color: #009999;
}

.button {
 width: 90px;
 height: 30px;
 background-color: red;
 margin-left: 50px;
}

i would like if i click RED .button then GREEN .show show me over the red button and if i click outside GREEN .show then this hide.

LIVE: http://jsfiddle.net/YeE4p/1/

Is this somewhat close to what you are looking for? http://jsfiddle.net/neilheinrich/YeE4p/6/

I had to change the #show div to be absolutely positioned and use this javascript:

$('.button').click(function(){

  var $show = $('#show');
  var position = $(this).offset()

  $show.css({
    "left": position.left + "px", 
    "top":position.top + "px"
  }).show();

  $(window).bind("mousedown", function(e){
    if (!($(e.target).attr("id") === "show")) {
      $("#show").hide();
      $(window).unbind("mousedown");
    }
  });
})

Try this out

http://jsfiddle.net/Quincy/YeE4p/4/

$('.button').click(function(event){
    $('#show').show();
    event.stopPropagation();
})

$('body').click(
    function(){
    $('#show').hide();
}
)   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM