- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在创建响应式锦标赛括号树网页。
我的问题是我想用一条装饰线将每个支架“每个支架都是它自己的一个 div”连接到下一个支架,一般来说,我想要两个连接两个 div 和一条我可以装饰的线。
例子1
例子2
我尝试使用 CanvasRenderingContext2D但我并没有太多运气,或者至少不知道如何充分利用它
我希望能够将两个括号/div 与一条可以 flex 和移动的线连接起来,“由开发人员而非用户”进行设计。
最佳答案
<div style="position:absolute; left:0; top:0; width: 100px; height: 50px; background:red;"></div>
<div style="position:absolute; left:250px; top:150px; width: 100px; height: 50px; background: blue;"></div>
<svg style="position:absolute; left:0; top:0;" width="300" height="300">
<line x1="100" y1="50" x2="250" y2="150" stroke="black"/>
</svg>
示例:
在 app.component.html 文件中:
<div class="cont">
<div *ngFor="let item of arr_item; index as i" class="block d-flex align-items-center justify-content-between">
<div class="d-flex flex-column" #left>
<div *ngFor="let val of item.left" class="box box-left">
{{val}}
</div>
</div>
<div class="d-flex flex-column align-items-end" #right>
<div *ngFor="let val of item.right" class="box box-right">
{{val}}
</div>
</div>
</div>
<svg style="position: absolute; z-index: -1; width:100%; height:100%; top: 0; left: 0;">
<polyline *ngFor="let item of polylines"
[attr.points]="item.points"
[attr.fill]="item.fill"
[attr.stroke]="item.stroke"
[attr.stroke-width]="item.strokeWidth"
/>
</svg>
</div>
在 app.component.css 文件中:
.cont {
position: relative;
}
.box {
padding: 10px;
border: 1px solid #292929;
width: fit-content;
margin: 10px;
max-width: 200px;
}
.block {
margin: 10px;
}
在 app.component.ts 文件中:
import {
AfterViewInit,
Component,
ElementRef,
OnInit,
QueryList,
ViewChildren
} from "@angular/core";
export class Polyline {
points: string;
fill: string;
stroke: string;
strokeWidth: number;
constructor(
points?: string,
fill?: string,
stroke?: string,
strokeWidth?: number
) {
this.points = points || "";
this.fill = fill || "none";
this.stroke = stroke || "blue";
this.strokeWidth = strokeWidth || 3;
}
}
@Component({
selector: "my-app",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent implements OnInit, AfterViewInit {
arr_item = [
{
left: ["Lorem Ipsum", "ABC"],
right: ["Hello World", "Hello"]
},
{
left: [
"Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
"Lorem Ipsum is simply dummy text"
],
right: [""]
},
{
left: [
"",
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s"
],
right: ["Rainbow"]
}
];
@ViewChildren("left", { read: ElementRef }) left: QueryList<ElementRef>;
@ViewChildren("right", { read: ElementRef }) right: QueryList<ElementRef>;
polylines: Polyline[] = [];
ngAfterViewInit() {
this.drawLines();
}
ngOnInit(): void {
window.addEventListener("resize", () => {
this.drawLines();
});
}
getPos_line(ele) {
var className = ele.getAttribute("class");
if (className.indexOf("left") !== -1) {
return {
x: Math.round(ele.offsetLeft + ele.offsetWidth),
y: Math.round(ele.offsetTop + ele.offsetHeight / 2)
};
} else {
return {
x: Math.round(ele.offsetLeft),
y: Math.round(ele.offsetTop + ele.offsetHeight / 2)
};
}
}
getMaxX_Left(arr: any) {
if (arr.length >= 1) {
var maxX = this.getPos_line(arr[0]).x;
for (var i = 0; i < arr.length; i++) {
var posLine = this.getPos_line(arr[i]);
if (posLine.x > maxX) {
maxX = posLine.x;
}
}
return maxX;
} else {
return null;
}
}
getMinX_Right(arr: any) {
if (arr.length >= 1) {
var minX = this.getPos_line(arr[0]).x;
for (var i = 0; i < arr.length; i++) {
var posLine = this.getPos_line(arr[i]);
if (posLine.x < minX) {
minX = posLine.x;
}
}
return minX;
} else {
return null;
}
}
getCenY(left, right) {
if (left.offsetHeight >= right.offsetHeight) {
return Math.round(left.offsetTop + left.offsetHeight / 2);
} else {
return Math.round(right.offsetTop + right.offsetHeight / 2);
}
}
drawLines() {
this.polylines = [];
for (var i = 0; i < this.arr_item.length; i++) {
var polylines_temp: Polyline[] = [];
var left_children = this.left.get(i).nativeElement.children;
var right_children = this.right.get(i).nativeElement.children;
var left_childrenLen = left_children.length;
var right_childrenLen = right_children.length;
var maxX_left = this.getMaxX_Left(left_children);
var minX_right = this.getMinX_Right(right_children);
var cenY = this.getCenY(
this.left.get(i).nativeElement,
this.right.get(i).nativeElement
);
var cenX = Math.round((maxX_left + minX_right) / 2);
var space = 0;
if (left_childrenLen > 1 && right_childrenLen > 1) {
space = 10;
}
for (var j = 0; j < left_childrenLen; j++) {
var posLine = this.getPos_line(left_children[j]);
polylines_temp.push(
new Polyline(`
${posLine.x},${posLine.y}
${cenX - space},${posLine.y}
${cenX - space},${cenY}
${cenX},${cenY}
`)
);
}
for (var j = 0; j < right_childrenLen; j++) {
var posLine = this.getPos_line(right_children[j]);
polylines_temp.push(
new Polyline(`
${cenX},${cenY}
${cenX + space},${cenY}
${cenX + space},${posLine.y}
${posLine.x},${posLine.y}
`)
);
}
this.polylines = this.polylines.concat(polylines_temp);
}
}
}
关于html - 如何在 Angular 中用线条连接两个 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66600951/
有人可以向我解释该声明在C++中的含义吗?我从未见过这样的声明,只是对它的含义和作用感到困惑: int ix((dx > 0) - (dx > 1)); 最佳答案 您可以在括号或花括号中使用初始化程序
我有一个带有单词的mysql数据库。我用 while 语句打印所有单词。所以我觉得: 马铃薯番茄生菜 一切正常,但我想按长度对单词进行排序。我试过: if(strlen($go['words']) =
我忠实的路径遍历方法不再有效——它将空格视为分隔符。好久没做批处理编程了。 使用 FOR 循环时,唯一允许使用分隔符的是 FOR/F 选项。 我不想创建一个包含路径的临时文件,希望做如下的事情: C:
新建一个表: ? 1
我有一些带有多行块的文本文件,例如 2011/01/01 13:13:13,, Some Certain Text,=, [ certain text [
我想在 Vim 中文件的不同部分之间进行一些很好的分离: 我想用#'s 填充一行,然后在中间写上我的标题: ############################# 居中标题############
我该如何逃生 "*"至 "\*"在clojure?似乎无法让它工作: (s/replace "A*B" #"*" "*")生产 "A*B" (当然) (s/replace "A*B" #"*" "\*
这周我一直在努力更熟悉 C。我一直在阅读C Primer Plus (5th Edition) 但是我仍然在使用变量和指针时遇到了一些麻烦。 这是我用来测试的脚本: int main (int arg
在 Dart 中,初始化 List 有什么区别?使用 new 运算符并使用文字对其进行初始化? 情况1: List args = new List(2); args[0] = 1; args[1] =
我有一个字符向量,如下所示: "Internet" "Internet" "-1" "-5" "Internet" "Internet" 我想替换所有负数值的值(-1、-5 等
我有一个名为 gen 的数据框,如下所示 A B C D E 1 NA 4.35 35.3 3.36 4.8
我有一个字符向量,如下所示: "Internet" "Internet" "-1" "-5" "Internet" "Internet" 我想替换所有负数值的值(-1、-5 等
我想知道为什么 CMake 中的变量经常用美元符号和大括号括起来。例如,我看到这个电话in a CMake tutorial . include_directories(${PROJECT_BINAR
我正在尝试做这样的事情 $this->db->count_all("grant_money")->where('id',5); 这可能吗? 如果有任何其他方法可以做到这一点,请告诉我。谢谢 我想像上面
为什么这是有效的: int a = 5; int *aPtr = &a; printf("%i", *aPtr); 但这不是: int a = 5; int aPtr = &a; printf("%i
假设我有一个格式为“11.23.13”的日期字符串,我想用“/”替换每个点,使其看起来像“11/23/13”。 这是我的代码,但它无法正常工作,因为正则表达式看到“.”并将其解释为匹配每个字符而不是新
如何在键盘输入的字符处打印*? 例子: 如果我在控制台中输入:mouli,那么它应该将 m 替换为 *,然后是 o用 * 等等。 最佳答案 使用标准 API 无法解决此问题。如果这确实是一个明确的要求
我最近开始学习 Javascript,同时对卡在这段代码中的代码进行了一些实验: var k = { ab: "hi", func: function() { cons
我需要用“.”替换第一列中的重复项 例如: name1 name1 name1 name2 name2 name3 name3 我需要输出: name1 . . name2 . name3 . 我有这
我有以下两个表 education 和 jobs,每个表都有时间戳字段。在续集语句中,我想选择并确定两个表中保存的两个时间戳中哪个是最新的。 我已经尝试了以下但并不愉快; SELECT e.Sta
我是一名优秀的程序员,十分优秀!