简体   繁体   中英

How to rotate gradient using SVG.js?

How to rotate gradient using SVG.js? I tried

var gradient = draw.gradient('linear', function(stop) {
    stop.at(0, '#f2b181')
    stop.at(1, '#de6d1e')
}).rotate(45);

but with no effect.

Linear gradients can be rotated by using the from() and to() methods. So to achieve a 45 degrees rotation, your code would be:

var gradient = draw.gradient('linear', function(stop) {
  stop.at(0, '#f2b181')
  stop.at(1, '#de6d1e')
}).from(0, 0).to(1, 1)

Here is a fiddle so you can play with it: http://jsfiddle.net/wout/ZhsFD/

But I can see the need for the rotate() method, it would be a nice addition to the api. I will include it in the next release.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM