- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在从数据库中提取一种具有特定起点和特定终点的 Div 时间线。其中一些重叠,其中一些可以彼此相邻安装。
最终我想将它们滑动在一起,使其尽可能紧凑,如下所示:
我怀疑如何应对这一挑战:通过服务器端 (php) 脚本或使用一些 javascript float 脚本。 或者当然是完全不同的方法
有人能把我推向正确的方向吗?
编辑::重要的是,因为它是一个时间线,所以 div 的水平位置保持不变。因此,将所有 div float 到左侧或内联阻止它们是没有选择的 :)
我的数据库设置:
id | name | start | end
1 | a | 2 | 7
2 | b | 5 | 10
etc
最佳答案
<!DOCTYPE html>
<html>
<!--
Created using jsbin.com
Source can be edited via http://jsbin.com/udofoq/26/edit
-->
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<style id="jsbin-css">div.blue {
background-color: #a4dcdf;
}
div.orange {
background-color: #fd9226;
}
div.green {
background-color: #88b37e;
}
div.yellow {
background-color: #d8d03f;
}
div.red {
background-color: #c16558;
}
div.grey {
background-color: #cdcdcd;
}
div.hours1{
top: 0px;
left: 10px;
width: 100px;//(110-10)
}
div.hours2{
top: 30px;
left: 80px;
width: 50px;
}
div.hours3{
top: 60px;
left: 120px;
width: 50px;
}
div.hours4{
top: 90px;
left: 5px;
width: 70px;
}
div.hours5{
top: 120px;
left: 110px;
width: 30px;
}
div.hours6{
top: 150px;
left: 130px;
width: 70px;
}
div.hours {
position: absolute;
height:20px;
color: white;
text-align:center;
border:white;
-webkit-box-shadow: 3px 3px 6px 2px rgba(00, 00, 00, .2);
box-shadow: 3px 3px 6px 2px rgba(00, 00, 00, .2);
font: bold 18px Arial, Helvetica, Geneva, sans-serif;
line-height:20px;
}
button{
position:static;
margin-top:200px;
}
.collapse,
.overlap1,
.overlap2,
.overlap3,
reset{
float:left;
}
</style></head>
<body>
<div class="hours hours1 orange">A</div>
<div class="hours hours2 yellow">B</div>
<div class="hours hours3 blue">C</div>
<div class="hours hours4 green">D</div>
<div class="hours hours5 red">E</div>
<div class="hours hours6 grey">F</div>
<button class="collapse">collapse</button>
<button class="overlap1">sort</button>
<button class="reset">reset</button>
<script>
data1 = [
[1, 10, 110],
[2, 80, 130],
[3, 120, 170],
[4, 5, 70],
[5, 110, 140],
[6, 130, 180]
];
//just added for console output not needed
var divider="";
for (var i = 0; i < 80; i++) {
divider += "_";
}
console.log(divider);
console.log("ORIGINAL ARRAY DATA1:", data1);
//add a column to keep track of the row, to start set it to row 1
data1 = $.each(data1, function(index, value) {
value[3] = 0;
});
console.log(divider);
console.log("ORIGINAL dataA WITH ADDED COLUMN:", data1);
function timelinesort(dataA){
//make a new Array to store the elements in with their new row number
var dataB = dataA.slice(0, 1);
console.log(divider);
console.log("INITIALIZED dataB WITH FIRST ELEMENT FROM dataA:", dataB);
//initialize the counter
var counter = 0;
console.log(divider);
console.log("INITIALIZED ROUNDS COUNTER:", counter);
dataA = $.map(dataA, function(value1, index1) {
//increment counter with 1
counter++;
console.log(divider);
console.log("INCREMENTED ROUNDS COUNTER:", counter);
dataA = $.map(dataA, function(value2, index2) {
//exclude comparing an element with itself
if(value2 != dataB[0]) {
//check to see if elements overlap
if(value2[2] >= dataB[0][1] && value2[1] <= dataB[0][2]) {
console.log(divider);
console.log("Round " + counter + " from dataA: [" + value2 + "] overlaps with " + dataB[0] + " incrementing row counter with 1");
//increment the value in column 3 (row counter) of the array
value2[3]++;
console.log(divider);
console.log("Now the dataA has changed to this:", dataA);
console.log("Meanwhile data1 has changed to this:", data1);
} else {
//if no overlap occurs check if the element is not already in the dataB array and if not check if it doesn't overlap with the existing elements
if($.inArray(value2, dataB) == -1) {
$.each(dataB, function(index3, value3) {
if(value3[2] >= value2[1] && value3[1] <= value2[2]) {
console.log(divider);
console.log("Round " + counter + " from dataA: [" + value2 + "] overlaps with " + value3 + " incrementing row counter with 1");
dataB.pop();
//increment the value in column 3 (row counter) of the array
value2[3]++;
} else {
//if no overlap occurs add the value to dataB
dataB.push(value2);
console.log(divider);
console.log("Added [" + value2 + "] to dataB and now dataB has changed to this: ", dataB);
}
});
} else {
dataB.push(value2);
console.log("Added [" + value2 + "] to dataB and now dataB has changed to this: ", dataB);
}
}
}
return [value2];
});
dataA = jQuery.grep(dataA, function(item) {
return jQuery.inArray(item, dataB) < 0;
});
if(dataA.length >= 1) {
dataB.unshift(dataA[0]);
dataB = dataB.splice(0, 1);
} else {
dataA = [];
}
});
}
//run the function
timelinesort(data1);
console.log(divider);
console.log("Finally the data1 has changed to this:", data1);
$(".collapse").click(function() {
$.each(data1, function(index, value) {
$("div.hours" + (index + 1)).animate({
"top": 0
}, "slow");
});
});
$(".overlap1").click(function() {
$.each(data1, function(index, value) {
console.log("div.hours" + (index + 1) + ":" + (value[3]) * 26);
$("div.hours" + (index + 1)).animate({
"top": (value[3]) * 26
}, "slow");
});
});
$(".reset").click(function() {
$.each(data1, function(index, value) {
$("div.hours" + (index + 1)).removeAttr('style');
});
});
</script>
</body>
</html>
我所做的是将所有行折叠到第一行,然后检查哪些行与该行的原始重叠,如果是,则在重叠的行上增加行号,然后转到下一行并重复该过程,直到所有元素整齐地堆叠。
您仍然需要清理 javascript/jquery 的东西并将其放入一个不错的函数中。但作为概念证明,它似乎有效
工作示例:
http://jsbin.com/udofoq/26/watch
或
关于php - 垂直对齐 div 但保持水平位置不变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13695028/
我有 2 个表 t1,其中存储价格和项目类型以及一个 ENUM 值和 t2,其中存储销售数量。我有一个计算总销售额(价格 * 数量)的查询,但我需要计算两个结果数字之间的差值。 两个数之差的计算公式应
我在使用 zsh 运行 Big Sur 11.2 的 Mac 上更改运行的 java 版本时遇到问题。我想将 Java 1.8 设置为默认设置,因此我使用以下命令设置 JAVA_HOME: $ uns
在下面的代码中,当我改变选择时,会有一个alert。我试图使该功能类似于当我单击 option 时它会显示 alert。 $(document).ready(function() { $("#x"
好吧,我正在制作一个简单的 react 游戏,我的代码如下。现在,当调用 startGame() 时,如果我注释掉 while 循环,一切都会发生,但是当我使用 thread.sleep(1000)
我目前正在尝试将 .plist 文件中的 CFBundleURLTypes 的值更改为新值,但似乎没有任何效果,并且如果我调用,旧值仍然存在 NSLog(@"%@", [[NSBundle mainB
我正在尝试使用 Jsoup 中的解析函数来解析 html 字符串。 我尝试阅读了很多相关的帖子以及API,但仍然没有找到答案。 String html = ""others"; Docume
我正在尝试为水平列表项关闭设置动画alpha 动画有效,layoutparam 值也随时间减少但出于某种原因,这并没有改变列表项的实际高度。 @Override protected void appl
双管道等于: MY_CONST ||= 42 运算符定义? MY_CONST = 42 unless defined? MY_CONST 为什么第二种方式更为普遍?第一个有什么缺点吗? 最佳答案 在一
我希望我的站点地址栏在访问子页面时不要更改其地址,它应该显示我的 index.html ,即使我进入 tosub 页面。 就像我打开 www.xyz.com我导航到它仍应显示的任何页面 www.xyz
我试图通过将购物车存储在数据库的表中来创建购物车,而不是使用内置的 CI 购物车类。我使用 sessionID 来识别一个访问者和另一个访问者。但是我发现sessionID在一段时间内一直在变化,连访
我面临一个奇怪的问题。一旦更改了.java文件-看来测试仍在使用该文件的早期版本(.class)。 从我的 Angular 来看,应该从.build文件夹中删除该类,并从新版本的.java文件重新编译
下面的R代码显示了一个关于向量组合的例子,之后,向量“c”的属性变成了字符。如何让它仍然保持属性为数字? a='aa';b='bb';c=c(1,2,3,4,5) dd=data.table(cbin
我一直在使用 Kinect 和语音识别,我注意到我无法让 AudioLevel 成员从我的 SpeechRecognitionEngine 对象中更改。 我成功地让命令被识别,所以我知道 kinect
大家好,我已经实现了通知功能。我对通知 ID 有疑问。 这是我的代码: protected void ShowNotification(String title, String text){ Noti
所以我第一次正确设置了 UIView 图层的阴影(它显示得非常好)但是当我尝试更改颜色时(没有别的,只是 layer.shadowColor)它不会在 View 中更新。它仍然显示原始颜色。我已经尝试
使用 java 我想在一个程序中生成一些随机值,然后在每次执行第二个程序时在其他程序中使用这些值。 这样做的目的是生成一次随机值,然后在以后每次运行程序时保持并保持它们不变。有可能吗?谢谢 最佳答案
我有几个组件,所有组件都继承了 JCheckBox 而没有覆盖它的任何内容,存储在一个 vector 中,然后遍历该 vector 并将每个组件添加到一个对话框中 CreateLists(); //
我有一个 UITabBarController。现在我想在其上方添加一个 View ,并在用户切换到另一个选项卡时使 View 保持不变。我尝试创建一个 UIViewController,并将 UIT
我正在使用 curses 来打印一个非常漂亮的控制台 UI,我需要它依赖于终端大小。为此,我阅读了 here ,我可以使用 shutil.get_terminal_size .所以我正在做这段代码:
我有一个jsfiddle here . fiddle 中有许多标记文本框。在文本框中输入一个数字,然后继续单击“添加问题”按钮。您将看到剩余的总分等于 10,但它不会改变。剩余分数的数量应该通过减去附
我是一名优秀的程序员,十分优秀!