Drawing grid with jQuery SVG produces 2px lines instead of 1px

后端 未结 3 876
礼貌的吻别
礼貌的吻别 2020-12-28 18:57

I know it\'s not the jQuery SVG library causing this issue, but when rendering horizontal or vertical SVG lines on integral x,y coordinates, lines are 2px wide instead of 1p

3条回答
  •  北海茫月
    2020-12-28 19:29

    A way to solve the problem is to apply some CSS to the lines:

    .thelines{
        shape-rendering:crispEdges
    }
    

    The spec chapter on shape-rendering property.

    Basically it turns off antialiasing for the lines, and the lines that are NOT straight horizontal or vertical may NOT look very pretty.

    But probably you'd better stick to adding .5 to the lines' coordinates, because browsers do what they are told to: the line is on exact coordinates and the stroke is painted on both sides of the line, half pixel here and half pixel there.

提交回复
热议问题