- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试为我的道路绘制一 strip 有 2 条线的分隔符。我已经尝试过只用 2 条平行线来制作它,但是当我制作我的道路曲线时,它看起来不太好。像这样:
小曲线:
大曲线:
因为它现在我只是在黑色背景线后面画一条白色背景线。但有时我的主路并不黑。如何使这些线之间的空间透明?
例子:
正常工作:
处理不同背景的道路:
您可以在下面的示例中拖动分隔符
var width = window.innerWidth;
var height = window.innerHeight;
var stage = new Konva.Stage({
container: 'container',
width: width,
height: height
});
var layer = new Konva.Layer();
var line = new Konva.Line({
points: [100, 100, 200, 200],
strokeWidth: 100,
stroke: 'black',
draggable: true,
});
var line_2 = new Konva.Line({
points: [400, 100, 500, 200],
strokeWidth: 100,
stroke: 'red',
draggable: true,
});
const group_sep = new Konva.Group({
draggable: true,
});
var sep_1 = new Konva.Line({
points: [100, 100, 200, 200],
strokeWidth: 20,
stroke: 'green',
});
var sep_2 = new Konva.Line({
points: [100, 100, 200, 200],
strokeWidth: 10,
stroke: '#000000',
});
group_sep.add(sep_1);
group_sep.add(sep_2);
layer.add(line);
layer.add(line_2);
layer.add(group_sep);
stage.add(layer);
layer.draw();
<script src="https://unpkg.com/konva@4.0.16/konva.min.js"></script>
<div id="container"></div>
最佳答案
您可以使用 blend mode通过 globalCompositeOperation
从另一行“剪切”一行。
const group_sep = new Konva.Group({
draggable: true,
});
var sep_1 = new Konva.Line({
points: [100, 100, 200, 200],
strokeWidth: 20,
stroke: 'green',
});
// destination-out will cut line from previous drawings
var sep_2 = new Konva.Line({
points: [100, 100, 200, 200],
strokeWidth: 10,
stroke: '#000000',
globalCompositeOperation: 'destination-out'
});
但是您应该知道 destination-out
会从 Canvas 上所有以前的绘图中剪切您的线条。这意味着它也可以剪切背景。要解决这些问题,您可以将带有线条的组移动到另一个 Konva.Layer
或只缓存该组:
group_sep.cache();
注意:记得每次更改行时重新缓存到组。
关于javascript - Konva 中的平行线分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58661196/
我正在尝试绘制与附件中的主线有偏移的线条。 我的代码有问题。它在线路上产生交点和尖点。 (附件) 也许有人可以帮助我处理这段代码,提供我可以遵循的任何工作示例。 // LEFT SIDE OF MAI
我在使用 opencv/python 进行对象检测时遇到了一些问题。 如果你看图片,我已经知道两个绿色框的四个角。我要检测的对象是红色内衬的对象,一种软管形状。 我的计划是从绿色盒子中获取软管的宽度
我正在我的 Mac 操作系统上的 Jupyter notebook 上编写一个 python 脚本,我正在尝试连接到一个本地数据库,该数据库位于我的 Parallels Windows 操作系统上,该
我需要解析 10 个网页,并捕捉它们的主要内容。所以我正在使用 Node 可读性并且不想重写相同的函数(仅 url 更改)10 次。最后,我必须计算内容长度。我如何使用循环或任何其他想法来做到这一点?
我是一名优秀的程序员,十分优秀!