【问题标题】:Drawing a rectangle with dashed lines using Rafael.js使用 Raphael.js 绘制带虚线的矩形
【发布时间】:2013-04-01 11:44:54
【问题描述】:

我正在使用 Rafael.js 在图像上绘制矩形。我设置描边颜色的问题是背景可能是深色或浅色或任何颜色。我认为处理这个问题的最好方法是使用虚线。然而这个电话

circle = Canvas.paper.rect(left, topCoord, width, height).attr({stroke-dasharray:"---"});

不起作用。 Firebug(在 FireFox 20.0 上)返回一条错误消息,指出我的 .js 文件中的现有函数不存在。看来 stroke-dasharray 对矩形无效。

【问题讨论】:

    标签: javascript svg firebug


    【解决方案1】:

    “stroke-dasharray”的值为:

    "-"     [shortdash]
    "."     [shortdot]
    "-."    [shortdashdot]
    "-.."   [shortdashdotdot]
    ". "    [dot]
    "- "    [dash]
    "--"    [longdash]
    "- ."   [dashdot]
    "--."   [longdashdot]
    "--.."  [longdashdotdot]
    

    【讨论】:

      【解决方案2】:

      基本 JavaScript 错误:

      {stroke-dasharray:"---"}
      

      应该是:

      {"stroke-dasharray":"---"}
      

      另外:"---" 不是 stroke-dasharray 支持的值;应该是:

      {"stroke-dasharray":"--"}
      

      【讨论】:

      • 谢谢。这使错误消失了,但我仍然得到矩形的实线黑线。谢谢,彼得。
      • 查看Raphael reference 我不认为三个破折号是一个有效的选择。试试两个:"--"
      • 这适用于获得虚线。非常感谢!要获得两种不同的颜色,我似乎需要两个调用:一个带有 {"stroke-dasharray":"--"} 和一个带有 {"stroke":"white", "stroke-dasharray":"-.." }。非常感谢!
      【解决方案3】:

      没有“---”,可能的笔划破折号:[“”, “-”, “.”, “-.”, “-..”, “. ”, “- ”, “--”, “- .”, “--.”, “--..”]

      为描边着色的一种方法是使用 HSV 或 HSL 空间,然后选择相反(或附近)的光谱。尝试来自Given an RGB value, how do I create a tint (or shade)?的答案

      【讨论】:

      猜你喜欢
      • 2021-01-24
      • 2014-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多