【问题标题】:SVG/Angular: rings with different shadeSVG / Angular:具有不同阴影的环
【发布时间】:2021-11-17 11:48:17
【问题描述】:

我一直在寻找一种解决方案,可以绘制戒指并使每个戒指都具有不同的色调。

结果是我想要的......但我不知道它为什么会起作用。我希望每个戒指都具有相同的颜色。

???

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  template: `

<svg [attr.height]="dimension" [attr.width]="dimension" [attr.viewBox]="'-' + dimension + ' -' + dimension + ' ' + dimension * 2 + ' ' + dimension * 2">
 <circle [attr.cx]="0" [attr.cy]="0" [attr.r]="dimension" [attr.fill]="foo()"><title>{{ foo () }}</title></circle>
 <circle [attr.cx]="0" [attr.cy]="0" [attr.r]="dimension/100*50" [attr.fill]="foo ()"><title>{{ foo () }}</title></circle>
 <circle [attr.cx]="0" [attr.cy]="0" [attr.r]="dimension/100*10" [attr.fill]="foo ()"><title>{{ foo () }}</title></circle>
</svg>
`
})
export class AppComponent
{
  dimension : number = 500;


  foo ()
  {
    return "#" + 0xBBAABB;
  }
}

【问题讨论】:

    标签: angular svg


    【解决方案1】:

    这是因为三个圆圈在某些区域相互重叠,从而产生不同的阴影。如果您尝试在各自的 svg 中将这 3 个圆圈分开,您会发现它们具有相同的颜色。

    查看我创建的stackblitz

    【讨论】:

    • 我不知道填充颜色确实受背景影响。
    • 是的,它确实会影响填充颜色。
    • 你能告诉我是否可以在没有这种效果的情况下使填充 100% 重叠吗?
    • 做了一些测试,似乎并不总是重叠。 stackoverflow.com/questions/69312736/…
    • 是的,我看到了你的问题。它不起作用的原因是因为您没有使用具有透明度的颜色。例如:浅绿色的十六进制颜色是#90EE90,如果您尝试将其直接添加到您的 svg 填充中,它将无法按预期工作。您可以在该十六进制的末尾添加 80 以使其透明。在原始代码中检查您的填充颜色,与您在 bar() 函数中使用的 #AAAAAA 相比,它使用的是具有透明度的不同十六进制。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-13
    • 1970-01-01
    • 2011-12-19
    • 1970-01-01
    • 2016-07-19
    • 1970-01-01
    相关资源
    最近更新 更多