如何使用 CSS 为我的网站制作最小化、最大化和关闭按钮
How do you make minimize, maximize, and close buttons for my website with CSS
我想为我正在创建的网站上的模式框制作最小化、最大化和关闭 按钮。我希望它们看起来像我网站上的 Windows 7 window 个按钮。我曾尝试在网上搜索帮助,但 none 个网站给了我想要的东西。请帮助我构建按钮并使用它们。
您最好的选择是模态库或其中包含模态的框架(例如 bootstrap)。
但是,如果您坚持要自己制作,那么像这样的东西会让您入门。这其中的要点是:
- 您需要一个 "header" 与内容
分开的模式
- 您需要 JavaScript(jQuery 会对此有所帮助)来控制动画
- 这是我拼凑的东西,但这些原则将适用于你构建的任何东西
- 最小化需要隐藏内容,而不是 header
- 最大化需要显示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>
我想为我正在创建的网站上的模式框制作最小化、最大化和关闭 按钮。我希望它们看起来像我网站上的 Windows 7 window 个按钮。我曾尝试在网上搜索帮助,但 none 个网站给了我想要的东西。请帮助我构建按钮并使用它们。
您最好的选择是模态库或其中包含模态的框架(例如 bootstrap)。
但是,如果您坚持要自己制作,那么像这样的东西会让您入门。这其中的要点是:
- 您需要一个 "header" 与内容 分开的模式
- 您需要 JavaScript(jQuery 会对此有所帮助)来控制动画
- 这是我拼凑的东西,但这些原则将适用于你构建的任何东西
- 最小化需要隐藏内容,而不是 header
- 最大化需要显示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>