在当前 div 上显示隐藏的 div 并隐藏下一个 div

发布于 2024-12-12 03:41:10 字数 869 浏览 0 评论 0原文

<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;
}

我希望如果我单击红色.按钮,然后单击绿色.show,则在红色按钮上显示我,如果我单击外部绿色.show,则此隐藏。

直播: http://jsfiddle.net/YeE4p/1/

<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/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

帅哥哥的热头脑 2024-12-19 03:41:10

这是否有点接近您正在寻找的内容?
http://jsfiddle.net/neilheinrich/YeE4p/6/

我必须更改 #显示 div 绝对定位并使用以下 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");
    }
  });
})

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");
    }
  });
})
小…红帽 2024-12-19 03:41:10

试试这个

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

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

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

Try this out

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

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

$('body').click(
    function(){
    $('#show').hide();
}
)   
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文