how to use attr's stroke-dasharray,stroke-linecap,stroke-linejoin in raphaeljs

后端 未结 4 1862
醉话见心
醉话见心 2020-12-08 08:31

Can anyone give me an example of these attributes in action: stroke-dasharray, stroke-linecap, stroke-linejoin i tried using them, but i don\'t quite understand the sente

4条回答
  •  無奈伤痛
    2020-12-08 09:09

    Please note that this answer covers only stroke-dasharray and is a supplement to answer by Phrogz.
    Raphael does not provide a lot of freedom to set stroke-dasharray as stated by user568458 and as I needed it to work like other svg creators I did a little tweak in raphael.js to accommodate all possible stroke-dasharray values.

    addDashes = function (o, value, params) {
            var nvalue = dasharray[Str(value).toLowerCase()];
            if (nvalue!==undefined) {
                var width = o.attrs["stroke-width"] || "1",
                    butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
                    dashes = [],
                    i = nvalue.length;
                while (i--) {
                    dashes[i] = nvalue[i] * width + ((i % 2) ? 1 : -1) * butt;
                }
                $(o.node, {"stroke-dasharray": dashes.join(",")});
            }else{
                $(o.node, {"stroke-dasharray": Str(value).toLowerCase()});
            }
        }
    

    Replacing the previous code in the file just below where dasharray object is defined.

提交回复
热议问题