Div元素滚动到另一个Div元素的上方而不是下方
Div element is scrolling over instead of underneath another div element
我试图得到一个项目列表滚动下另一个div元素在一个板,但现在它正在滚动它。我试过使用CSS z-index属性,但它不适合我。我不确定我是否正确使用它,因为这是我第一次尝试在z轴上定位元素。
HTML:<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="bootstrap.min.css">
<script src="update.js"></script>
<script src="scrollDrag.js"></script>
</head>
<body onload="update()">
<ul class="board list-group" style="overflow:hidden">
<div id="lb"></div>
<div id="sub-lb"></div>
</ul>
</body>
</html>
JS:(update.js)
function update() {
"use strict";
// setTimeout(function () {update(); }, 10000);
// List of variables
var xmlhttp, resultString, unorderedList, listItem, infoText, arrayInfo, info,
i, temp, span;
// code for IE7+, Firefox, Chrome, Opera, Safari
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp = new window.ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
// Split php response text into an array (contains the top 50 of leaderboard)
resultString = xmlhttp.responseText;
arrayInfo = resultString.split(";");
// Set up the rank, name, total headings
listItem = document.createElement("li");
listItem.setAttribute("class", "list-group-item heading");
listItem.setAttribute("style", "background-color:#0066FF");
infoText = document.createTextNode("Rank");
span = document.createElement("span");
span.setAttribute("style", "margin-left:1%");
span.appendChild(infoText);
listItem.appendChild(span);
infoText = document.createTextNode("Name");
span = document.createElement("span");
span.setAttribute("style", "position:absolute; left:35%");
span.appendChild(infoText);
listItem.appendChild(span);
infoText = document.createTextNode("Zenny");
span = document.createElement("span");
span.setAttribute("style", "float:right");
span.appendChild(infoText);
listItem.appendChild(span);
document.getElementById("lb").appendChild(listItem);
// Loop through arrayInfo
for (i = 0; i < arrayInfo.length - 1; i += 1) {
// Split content of each index of arrayInfo and store it into a new array
// Split in form of rank, name, money
temp = arrayInfo[i];
info = temp.split(",");
// Create a new list item element
listItem = document.createElement("li");
listItem.setAttribute("class", "list-group-item");
listItem.setAttribute("style", "width:100%; font-size:150%");
// Create a new span element for rank
infoText = document.createTextNode(info[0]);
span = document.createElement("span");
span.setAttribute("style", "margin-left:2%");
span.appendChild(infoText);
listItem.appendChild(span);
// Create a new span element for name
infoText = document.createTextNode(info[1]);
span = document.createElement("span");
span.setAttribute("style", "position:absolute; left:35%");
span.appendChild(infoText);
listItem.appendChild(span);
// Create a new span element for money
infoText = document.createTextNode(info[2]);
span = document.createElement("span");
span.setAttribute("style", "float:right; margin-right:2%");
span.appendChild(infoText);
listItem.appendChild(span);
document.getElementById("sub-lb").appendChild(listItem);
}
}
};
xmlhttp.open("GET", "update.php", true);
xmlhttp.send();
return false;
}
scrollDrag.js文件只指定要滚动的元素,即"sub-lb",以及触摸&拖动事件,因此它不应该是问题的原因。
重复问题:元素"sub-lb"正在滚动元素"lb"当前,我不知道如何让它在下面滚动
看起来你正在使用stock Bootstrap css。从您提供的代码来看,据我所知,z-index似乎没有设置在任何地方。
对于测试,将style="z-index:xx"
添加到元素中,其中xx
是您选择的某个数字,确保较高的索引是您想要的顶部索引。
一旦你验证了这是有效的,你应该考虑包括一个覆盖css文件,其中包含所有的css自定义,这样你就可以避免内联样式并保持Bootstrap css的原样。
如果你已经尝试过这种方式,请邮政编码,因为在我看来,这将是最简单的方法来处理这个问题
相关文章:
- 如何在不影响其他元素的情况下扩展DIV
- DIV怎么能像Javascript中的另一个元素一样工作呢
- 循环对象时更新页面上的DIV元素
- 在DIV中动态插入HTML并访问新元素
- 单击javascript按钮显示/隐藏Div元素
- 如何确定滚动DIV中的可见DOM元素
- 范围和列表元素在 DIV 中换行
- Javascript 在提交时禁用 Div 元素
- 在 AJAX 调用中发送 DIV 元素的 ID
- 在具有特定ID的DIV中使用JavaScript动态添加HTML元素
- 使用JavaScript函数添加多个DIV元素
- 如果在Div元素外部单击,请关闭该元素
- 使用jQuery将列表中的元素集封装在DIV中
- 如何使用CSS3/JavaScript缩放DIV元素及其子元素以适应父元素
- 如何将SVG元素和Div放入图像中,以便用户可以下载
- 将DIV元素绑定到溢出滚动条
- 如何切换DIV元素的可见性
- jQuery - 将元素拖入 DIV / 或可排序元素
- Div在浏览器的检查元素中很暗,无法检索内容
- JavaScript/jQuery:如何获得元素(DIV)旋转后的实际原始位置