如何解决我需要几个月前的滚动条,但我需要在右侧带有名称的矩形以保持可见
我希望在几个月前显示滚动条,但我也希望始终显示右侧的名称。 我只想在主框中滚动。我只希望在屏幕的同一位置显示右侧。这是给我实习的没有一个客户的名字是真实的,所以我希望没有信息泄露。 有人可以帮我吗?
var canvas = document.querySelector('canvas');
canvas.width = 4000;
canvas.height = 2000;
var c = canvas.getContext('2d');
function display_client_in_canvas(item,index){
console.log(index);
}
var clientArray = {
1122: {
'name':'Harry Potter','id':1122,'startdate':1567980000,'enddate':1598824800
},11522: {
'name': 'Harry Pothead','id': 11522,'startdate': 1567580000,'enddate': 1568824800
},122: {
'name': 'Piet Klaas','id': 122,'startdate': 1567987000,'enddate': 1598824900
},12452: {
'name': 'Jan Klaas','id': 12452,'startdate': 1567947000,'enddate': 1598821900
},19452: {
'name': 'Piet Jan','id': 19452,'startdate': 1567917000,'enddate': 1598824100
},1123: {
'name':'Parry Hotter',11523: {
'name': 'Harry Knothead',123: {
'name': 'Piet Dwaas',12453: {
'name': 'Jan Dwaas',19453: {
'name': 'Piet Pan',1124: {
'name':'Parry Potter',11524: {
'name': 'Barry Pothead',124: {
'name': 'Piet Blaas',12454: {
'name': 'Jan Blaas','enddate': 1598821900
}
};
// Line
// Box
c.beginPath();
c.moveTo(50,100);
c.lineTo(1610,1500);
c.lineTo(50,100);
c.strokeStyle = "black";
c.stroke();
// Line left in the box
c.beginPath();
c.moveTo(150,100);
c.lineTo(150,1500);
c.strokeStyle = "black";
c.stroke();
// Line above
// Coloring the Months
c.beginPath();
c.fillStyle = "white";
c.fillRect(151,100,124,1399);
c.fillStyle = "#e7e7c7";
c.fillRect(274,111,1399);
c.fillStyle = "white";
c.fillRect(386,1399);
c.fillStyle = "#e7e7c7";
c.fillRect(510,122,1399);
c.fillStyle = "white";
c.fillRect(630,1399);
c.fillStyle = "#e7e7c7";
c.fillRect(754,1399);
c.fillStyle = "white";
c.fillRect(874,1399);
c.fillStyle = "#e7e7c7";
c.fillRect(998,1399);
c.fillStyle = "white";
c.fillRect(1122,1399);
c.fillStyle = "#e7e7c7";
c.fillRect(1242,1399);
c.fillStyle = "white";
c.fillRect(1366,1399);
c.fillStyle = "#e7e7c7";
c.fillRect(1486,1399);
var randXstart,randY,randXend,randXdashB,randXdashE;
// First line
randXstart = (Math.random() * 450) + 150;
randXend = randXstart + 800;
//if(randXstart > randXend) {
// var x = randXstart;
// randXstart = randXend;
// randXend = x;
//}
randY = 150;
c.beginPath();
c.strokeStyle = "red";
c.moveTo(randXstart,randY);
c.lineTo(randXend,randY);
c.stroke();
randY = 160;
c.beginPath();
c.strokeStyle = "red";
c.moveTo(randXstart,140);
c.lineTo(randXstart,randY);
c.stroke();
randY = 140;
c.beginPath();
c.strokeStyle = "red";
c.moveTo(randXend,160);
c.lineTo(randXend,randY);
c.stroke();
// Second line
randY = 250;
c.beginPath();
c.strokeStyle = "red";
c.moveTo(randXstart,randY);
c.stroke();
randY = 260;
c.beginPath();
c.strokeStyle = "red";
c.moveTo(randXstart,240);
c.lineTo(randXstart,randY);
c.stroke();
randY = 260;
c.beginPath();
c.strokeStyle = "red";
c.moveTo(randXend,240);
c.stroke();
// Third line
randY = 350;
c.beginPath();
c.strokeStyle = "red";
c.moveTo(randXstart,randY);
c.stroke();
randY = 360;
c.beginPath();
c.strokeStyle = "red";
c.moveTo(randXstart,340);
c.lineTo(randXstart,randY);
c.stroke();
randY = 360;
c.beginPath();
c.strokeStyle = "red";
c.moveTo(randXend,340);
c.stroke();
// Fourth line
randY = 450;
c.beginPath();
c.strokeStyle = "red";
c.moveTo(randXstart,randY);
c.stroke();
randY = 460;
c.beginPath();
c.strokeStyle = "red";
c.moveTo(randXstart,440);
c.lineTo(randXstart,randY);
c.stroke();
randY = 460;
c.beginPath();
c.strokeStyle = "red";
c.moveTo(randXend,440);
c.stroke();
// Fifth line
randY = 550;
c.beginPath();
c.strokeStyle = "red";
c.moveTo(randXstart,randY);
c.stroke();
randY = 560;
c.beginPath();
c.strokeStyle = "red";
c.moveTo(randXstart,540);
c.lineTo(randXstart,randY);
c.stroke();
randY = 560;
c.beginPath();
c.strokeStyle = "red";
c.moveTo(randXend,540);
c.stroke();
// Names clients
var first_timeline_y_pos = 150;
var vertical_space_per_timeline = 100;
function add_name_to_timeline(c,name,y_pos) {
c.beginPath();
c.fillStyle = 'black';
c.font = "12px Arial";
c.fillText(name,64,y_pos);
c.stroke();
}
var i = 0;
for (var client in clientArray) {
var client_data = clientArray [client];
var y_pos = first_timeline_y_pos + vertical_space_per_timeline * i;
add_name_to_timeline(c,client_data['name'],y_pos);
i++;
var s = new Date(client_data['startdate'] * 1000).toLocaleDateString("nl-NL");
console.log(s);
var d = new Date(client_data['enddate'] * 1000).toLocaleDateString("nl-NL");
console.log(d);
}
// Box above Box
c.beginPath();
c.moveTo(50,20);
c.lineTo(1610,20);
c.strokeStyle = "black";
c.stroke();
c.beginPath();
c.moveTo(50,20);
c.lineTo(50,100);
c.strokeStyle = "black";
c.stroke();
c.beginPath();
c.moveTo(150,20);
c.lineTo(150,100);
c.strokeStyle = "black";
c.font = "20px Arial";
c.fillText("Maanden",60,55);
c.font = "20px Arial";
c.fillText("2020",76,78);
c.stroke();
// January
c.beginPath();
c.moveTo(274,20);
c.lineTo(274,1500);
c.strokeStyle = "black";
c.font = "20px Arial";
c.fillText("Jan",196,65);
c.stroke();
// February
c.beginPath();
c.moveTo(386,20);
c.lineTo(386,1500);
c.strokeStyle = "black";
c.font = "20px Arial";
c.fillText("Feb",312,65);
c.stroke();
// March
c.beginPath();
c.moveTo(510,20);
c.lineTo(510,1500);
c.strokeStyle = "black";
c.font = "20px Arial";
c.fillText("Mar",430,65);
c.stroke();
// April
c.beginPath();
c.moveTo(630,20);
c.lineTo(630,1500);
c.strokeStyle = "black";
c.font = "20px Arial";
c.fillText("Apr",554,65);
c.stroke();
// May
c.beginPath();
c.moveTo(754,20);
c.lineTo(754,1500);
c.strokeStyle = "black";
c.font = "20px Arial";
c.fillText("Mei",674,65);
c.stroke();
// June
c.beginPath();
c.moveTo(874,20);
c.lineTo(874,1500);
c.strokeStyle = "black";
c.font = "20px Arial";
c.fillText("Jun",796,65);
c.stroke();
// July
c.beginPath();
c.moveTo(998,20);
c.lineTo(998,1500);
c.strokeStyle = "black";
c.font = "20px Arial";
c.fillText("Jul",924,65);
c.stroke();
// August
c.beginPath();
c.moveTo(1122,20);
c.lineTo(1122,1500);
c.strokeStyle = "black";
c.font = "20px Arial";
c.fillText("Aug",1042,65);
c.stroke();
// September
c.beginPath();
c.moveTo(1242,20);
c.lineTo(1242,1500);
c.strokeStyle = "black";
c.font = "20px Arial";
c.fillText("Sep",1164,65);
c.stroke();
// October
c.beginPath();
c.moveTo(1366,20);
c.lineTo(1366,1500);
c.strokeStyle = "black";
c.font = "20px Arial";
c.fillText("Okt",1288,65);
c.stroke();
// November
c.beginPath();
c.moveTo(1486,20);
c.lineTo(1486,1500);
c.strokeStyle = "black";
c.font = "20px Arial";
c.fillText("Nov",1408,65);
c.stroke();
// December
c.beginPath();
c.moveTo(1610,1500);
c.font = "20px Arial";
c.fillText("Dec",1528,65);
c.stroke();
// Dashed lines
// First
randXdashB = randXend + 5;
randXdashE = (randXdashB + 200);
randY = 150;
c.beginPath();
c.strokeStyle = "red";
c.setLineDash([5,5]);
c.moveTo(randXdashB,randY);
c.lineTo(randXdashE,randY);
c.stroke();
randY = 160;
c.beginPath();
c.setLineDash([]);
c.strokeStyle = "red";
c.moveTo(randXdashB,140);
c.lineTo(randXdashB,randY);
c.stroke();
randY = 140;
c.beginPath();
c.setLineDash([]);
c.strokeStyle = "red";
c.moveTo(randXdashE,160);
c.lineTo(randXdashE,randY);
c.stroke();
// Second line
randXdashB = randXend + 5;
randXdashE = (randXdashB + 200);
randY = 250;
c.beginPath();
c.strokeStyle = "red";
c.setLineDash([5,randY);
c.stroke();
randY = 260;
c.beginPath();
c.setLineDash([]);
c.strokeStyle = "red";
c.moveTo(randXdashB,240);
c.lineTo(randXdashB,randY);
c.stroke();
randY = 240;
c.beginPath();
c.setLineDash([]);
c.strokeStyle = "red";
c.moveTo(randXdashE,260);
c.lineTo(randXdashE,randY);
c.stroke();
//Third line
randXdashB = randXend + 5;
randXdashE = (randXdashB + 200);
randY = 350;
c.beginPath();
c.strokeStyle = "red";
c.setLineDash([5,randY);
c.stroke();
randY = 360;
c.beginPath();
c.setLineDash([]);
c.strokeStyle = "red";
c.moveTo(randXdashB,340);
c.lineTo(randXdashB,randY);
c.stroke();
randY = 340;
c.beginPath();
c.setLineDash([]);
c.strokeStyle = "red";
c.moveTo(randXdashE,360);
c.lineTo(randXdashE,randY);
c.stroke();
//Fourth line
randXdashB = randXend + 5;
randXdashE = (randXdashB + 200);
randY = 450;
c.beginPath();
c.strokeStyle = "red";
c.setLineDash([5,randY);
c.stroke();
randY = 460;
c.beginPath();
c.setLineDash([]);
c.strokeStyle = "red";
c.moveTo(randXdashB,440);
c.lineTo(randXdashB,randY);
c.stroke();
randY = 440;
c.beginPath();
c.setLineDash([]);
c.strokeStyle = "red";
c.moveTo(randXdashE,460);
c.lineTo(randXdashE,randY);
c.stroke();
//Fifth line
randXdashB = randXend + 5;
randXdashE = (randXdashB + 200);
randY = 550;
c.beginPath();
c.strokeStyle = "red";
c.setLineDash([5,randY);
c.stroke();
randY = 560;
c.beginPath();
c.setLineDash([]);
c.strokeStyle = "red";
c.moveTo(randXdashB,540);
c.lineTo(randXdashB,randY);
c.stroke();
randY = 540;
c.beginPath();
c.setLineDash([]);
c.strokeStyle = "red";
c.moveTo(randXdashE,560);
c.lineTo(randXdashE,randY);
c.stroke();
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>TimeLine</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<style type="text/css">
html,body
{
width:100%;
height:100%;
margin:0;
}
#parent {
width:4000px;
height:1000px;
border:1px solid #000;
overflow-x:scroll;
}
.canvas {
width:auto;
height:auto;
}
</style>
<div id="parent">
<canvas id="canvas" class="canvas" width="2500" height="3500">
</canvas>
</div>
<script src="Opdracht2.js"></script>
<script>
</script>
</body>
</html>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。