Jump to content
Search Community

Change svg gradient with object getters and setters

JamesGrubb test
Moderator Tag

Recommended Posts

Hello attempting and failing to animate an svg gradient. Im using svg.js and setting the gradient object using a gradientStops object

 

var gradientStops = {
  _start: 0,
  get start() {
    return this._start;
  },
  set start(value) {
    this._start = value;
  },
  _end: 1,
  get end() {
    return this._end;
  },
  set end(value) {
    this._end = value;
  }
};

var draw = new SVG().addTo("#svg").attr({
  viewBox: "0 0 100 100",
  class: "w-2/3 bg-red-50"
});
var gradient = draw.gradient("linear", function (add) {
  add.stop(gradientStops.start, "hsla(352, 99%, 90%, 1.00)");
  add.stop(gradientStops.end, "hsla(352, 99%, 50%, 1.00)");
});

var globe = draw.circle(50).fill(gradient).cx(50).cy(50);

gsap.to(gradientStops, {
  start: 1,
  end: 0,
  duration: 2,
  yoyo: true,
  repeat: -1
});

Thanks in advance

See the Pen gOLLezz?editors=0010 by limitedunlimited (@limitedunlimited) on CodePen

Link to comment
Share on other sites

Nothing what so ever. I imagine it must sound ungrateful when you give a response and it it is bounced back with what sounds like someone being picky. Im on a learning path of my own and thats why I was hopping to follow with this current code stack. Please do know that I am immensely appreciative of the support you give to the community.

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...