How to get a rotated linear gradient svg for use as a background image?

前端 未结 4 1337
心在旅途
心在旅途 2021-02-05 03:44

I\'ve seen a few questions dancing around this, so I hope this isn\'t too redundant. Ideally, I\'d like an image/svg+xml which scales to 100% of it\'s container. C

4条回答
  •  灰色年华
    2021-02-05 04:38

    Giel Berkers' solution in Javascript would be:

    // angle can be 0 to 360
    var anglePI = (angle) * (Math.PI / 180);
    var angleCoords = {
        'x1': Math.round(50 + Math.sin(anglePI) * 50) + '%',
        'y1': Math.round(50 + Math.cos(anglePI) * 50) + '%',
        'x2': Math.round(50 + Math.sin(anglePI + Math.PI) * 50) + '%',
        'y2': Math.round(50 + Math.cos(anglePI + Math.PI) * 50) + '%',
    }
    

提交回复
热议问题