【问题标题】:How do you make minimize, maximize, and close buttons for my website with CSS你如何使用 CSS 为我的网站制作最小化、最大化和关闭按钮
【发布时间】:2018-08-11 21:24:08
【问题描述】:

我想为我正在创建的网站上的模态框制作最小化、最大化和关闭按钮。我希望它们看起来像我网站上的 Windows 7 窗口按钮。我试过在网上搜索帮助,但没有一个网站给了我想要的东西。请帮我制作按钮并使用它们。

【问题讨论】:

  • “如何提问:1.您的问题是关于编程的吗?我们更喜欢可以回答的问题,而不仅仅是讨论。2.提供详细信息。分享您的研究。”

标签: css web-services button resize window


【解决方案1】:

您最好的选择是模态库或其中包含模态的框架(例如引导程序)。

但是,如果您坚持自己制作,这样的事情会让您开始。这其中的关键点是:

  • 您需要一个将“标题”与内容分开的模式
  • 您需要 JavaScript(jQuery 将在这方面提供帮助)来控制动画
  • 这是我拼凑起来的东西,但这些原则将适用于您构建的任何东西
    • 最小化需要隐藏内容,而不是标题
    • 最大化需要显示contnet,而不是header
    • 理想情况下,两个按钮都应该有一个点击动画来显示模态框的位置。

jQuery(document).ready(function($){
  $(document).on('click', '.min', function(){
    $(this).closest('.modal').find('.content').slideUp();
    $(this).closest('.modal').animate({'left':0,'bottom':0});
  });
  
  $(document).on('click', '.max', function(){
    $(this).closest('.modal').find('.content').slideDown();
    $(this).closest('.modal').animate({'left':'20px','bottom':'50%'});
  });
  
  $(document).on('click', '.close', function(){
    $(this).closest('.modal').fadeOut();
  });
});
.shield {
  position: absolute;
  width: 100vw;
  height: 100vh;
  background: rgba(0,0,0,.25);
  top: 0;
  left: 0;
  font-family: sans-serif;
}

.modal {
  position: absolute;
  bottom: 50%;
  left: 20px;
  background: #fff;
  border: 1px solid #ccc;
  box-shadow: 0 0 15px -5px rgba(0,0,0,.5);
  width: 600px;
}

.modal .header {
  padding: 8px 12px;
  position: relative;
}

.modal .header .buttons {
  position: absolute;
  right: 0;
  top: 9px;
}

.modal .header .buttons span {
  border-left: 1px solid #ccc;
  padding: 8px 20px;
  cursor: pointer;
}

.modal .header .buttons span:hover {
  background: #eee;
}

.modal .content {
  border-top: 1px solid #ccc;
  padding: 20px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
  <h1>Here's Content</h1>
  <p>Under the modal</p>
  <p>Under the modal</p>
  <p>Under the modal</p>
  <p>Under the modal</p>
</div>
<div class="shield">
  <div class="modal">
    <div class="header">
      <span>Modal Window</span>
      <span class="buttons"><span class="min">_</span><span class="max">[ ]</span><span class="close">X</span></span>
    </div>
    <div class="content">
    Here's modal pop-up content
    </div>
  </div>
</div>

【讨论】:

  • 谢谢!我可以使用帮助。
猜你喜欢
  • 2012-12-09
  • 2016-03-04
  • 2016-10-04
  • 1970-01-01
  • 2011-03-13
  • 2015-10-16
  • 2012-12-16
  • 1970-01-01
相关资源
最近更新 更多