如何插入一个弹出到一个Div
How to insert a Pop up into a Div
我一直在做一个弹出窗口,但我无法正确地将其放置在容器内…
$(document).ready(function() {
$('.show-popup').on('click', function() {
$('.popup').fadeIn();
});
$('.close_pop').on('click', function() {
$('.popup').fadeOut();
});
});
var max = true;
function expand_collapse(elem) {
var top_div = elem.parentNode.parentNode.parentNode;
if (max === false) {
elem.innerHTML = "▼";
top_div.classList.toggle("minimized", false);
top_div.classList.toggle("maximized", true);
max = true;
} else if (top_div.classList.contains("maximized")) {
elem.innerHTML = "▲";
top_div.classList.toggle("minimized", true);
top_div.classList.toggle("maximized", false);
max = false
}
}
function close_pop(elem) {
var top_div = elem.parentNode.parentNode.parentNode;
top_div.style.display = 'none';
if (top_div.classList.contains("maximized")) {
max = false;
}
};
.container {
height: 30px;
width: 100%;
position: fixed;
bottom: 0;
right: 0;
background-color: red;
}
.popup {
display: none;
}
.pop_out {
background: #333;
border-radius: 5px 5px 0 0;
box-shadow: 0px 0px 10px #000;
}
.minimized {
display: inline-block;
margin-right: 10px;
bottom: 0;
width: 250px;
height: 60px;
overflow: hidden;
}
.maximized {
top: 0;
position: fixed;
display: block;
width: auto;
height: auto;
}
.close_pop {
cursor: pointer;
color: #fff;
}
.close_pop:hover {
color: red;
}
.expand_collapse {
margin-right: 10px;
cursor: pointer;
color: #fff;
height: 3px;
}
.expand_collapse:hover {
color: #ccc;
}
a {
position: fixed;
top: 150;
}
<html>
<link href="./index.css" rel="stylesheet" type="text/css">
<a class="show-popup" href="#">CLICK HERE</a>
<!--Right Here -->
<div class="popup" style="position:fixed;bottom:0px;">
<div class="pop_out maximized">
<div style="padding:2px;position:relative;"> <span style="margin-left:10px;">Tab 1</span>
<span style="position:absolute;right:15px;">
<span class="expand_collapse" onclick="expand_collapse(this);">▼</span>
<span class="close_pop">×</span></span>
</div>
<div style="background:white;font-size:15px;padding:2px;">The standard Lorem Ipsum passage, used since the 1500s "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
laborum.
</div>
</div>
</div>
<div class="container">
text
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<script src="./index.js"></script>
</html>
我试图插入弹出到容器每当最小化按钮被点击。
将.popup
集装箱由position:fixed
改为position:absolute
在.minimized
类中添加以下css
.minimized {
position: relative;
z-index: 1;
vertical-align: bottom;
}
bottom
属性在指定position
为容器时起作用。
position:relative
在这种情况下很方便。
尝试降低高度(大约比红色div高)。
$(document).ready(function() {
$('.show-popup').on('click', function() {
$('.popup').fadeIn();
});
$('.close_pop').on('click', function() {
$('.popup').fadeOut();
});
});
var max = true;
function expand_collapse(elem) {
var top_div = elem.parentNode.parentNode.parentNode;
var fatherDiv=elem.parentNode.parentNode.parentNode.parentNode;
if (max === false) {
elem.innerHTML = "▼";
top_div.classList.toggle("minimized", false);
top_div.classList.toggle("maximized", true);
max = true;
fatherDiv.style.zIndex="2";
} else if (top_div.classList.contains("maximized")) {
elem.innerHTML = "▲";
top_div.classList.toggle("minimized", true);
top_div.classList.toggle("maximized", false);
max = false;
fatherDiv.style.zIndex="0";
}
}
function close_pop(elem) {
var top_div = elem.parentNode.parentNode.parentNode;
top_div.style.display = 'none';
if (top_div.classList.contains("maximized")) {
max = false;
}
};
.container {
height: 89px;
width: 100%;
position: fixed;
bottom: 0;
right: 0;
background-color: red;
}
.popup {
display: none;
}
.pop_out {
background: #333;
border-radius: 5px 5px 0 0;
box-shadow: 0px 0px 10px #000;
}
.minimized {
display: inline-block;
margin-right: 10px;
width: 100%;
height: auto;
overflow: auto;
z-index: 0;
top: 89px;
position: fixed;
}
.maximized {
top: 89px;
position: fixed;
display: block;
width: auto;
height: auto;
z-index: 2;
}
.close_pop {
cursor: pointer;
color: #fff;
}
.close_pop:hover {
color: red;
}
.expand_collapse {
margin-right: 10px;
cursor: pointer;
color: #fff;
height: 3px;
}
.expand_collapse:hover {
color: #ccc;
}
a {
position: fixed;
top: 150;
}
<html>
<link href="./index.css" rel="stylesheet" type="text/css">
<a class="show-popup" href="#">CLICK HERE</a>
<!--Right Here -->
<div class="popup" style="position:fixed;bottom:0px;z-index:2;">
<div class="pop_out maximized">
<div style="padding:2px;position:relative;"> <span style="margin-left:10px;">Tab 1</span>
<span style="position:absolute;right:15px;">
<span class="expand_collapse" onclick="expand_collapse(this);">▼</span>
<span class="close_pop">×</span></span>
</div>
<div style="background:white;font-size:15px;padding:2px;">The standard Lorem Ipsum passage, used since the 1500s "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
laborum.
</div>
</div>
</div>
<div class="container">
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<script src="./index.js"></script>
</html>
日志:
新的var fatherDiv,它是容器div "Popup";
添加"fatherDiv.style。zIndex='2'"设置Div在红色Div的前面(z-index工作就像一个层,就像2层纸)。
zIndex只作用于一个东西的主容器(在这种情况下,Popup Div,可能不工作在某些情况下的子);
在。minimize中添加"top"answers"position"规则,因为没有位置规则就不能使用top(我平衡位置只是为了显示这个结果,你可以在文件中平衡这个值)
告诉我你对这件事的看法
相关文章:
- 通过DRAGGABLE将一个DIV移动到另一个DIF下?(CSS,JQuery)
- 限制一个DIV出现在另一个特定大小的DIV中
- 使用jQuery将DIV放在另一个DIV上
- 只翻转一个DIV,而不是所有DIV都属于同一类
- 更改另一个 DIV 之前的 DIV 宽度
- JQuery 将一个 Div 值的百分比添加到另一个值
- jQuery - 在另一个 DIV 中定位特定的 DIV
- 选中复选框时仅重新加载一个DIV
- 动态创建一个DIV容器
- 在悬停时显示一个DIV,在悬停的另一个DIV.使用CSS
- 将DIV内容复制到另一个DIV
- 当调用DIV时,将一个DIV加载到另一个的顶部
- 通过点击隐藏DIV,并通过JavaScript显示另一个DIV
- 同时换掉两个Div,换成另一个Div并保持循环一段固定的秒数
- For循环只打印一个DIV标记.不是8个DIV标签
- 切换一个Div与按钮改变左边距属性
- 使用 javascript 在 DOM 中隐藏 DIV 中的文本,具体取决于另一个 DIV 中的文本
- 如何根据另一个 DIV 内容的可见性显示 DIV 内容
- DIV 滚动到达页脚(另一个 DIV)后停止滚动
- JQuery 滚动到滚动到下一个 DIV