svgdotjs / svg.js

The lightweight library for manipulating and animating SVG
https://svgjs.dev
Other
11.07k stars 1.08k forks source link

Text example not working #1265

Closed DwayneDibley closed 1 year ago

DwayneDibley commented 2 years ago

I tried the example code:

            var gui = SVG();
            var text = gui.text('This is just the start, ').move(500, 500)
            text.css({ cursor: 'pointer', fill: 'white' })

            text.build(true)  // enables build mode

            var tspan = text.tspan('something pink in the middle ').fill('#00ff97')
            text.plain('and again boring at the end.')

            text.build(false) // disables build mode

            text.animate('2s').fill('#f06')

It fails in the animate statement:

Uncaught TypeError: Type is not a constructor at ObjectBag.valueOf (Morphable.js:290:6) at Runner. (Runner.js:685:7) at Runner._run (Runner.js:451:34) at Runner.step (Runner.js:360:7) at Timeline._stepFn (Timeline.js:293:7) at _draw (Animator.js:87:6)

Looking at the code, Type is set to NaN. There is no check on the value of Type so that is probably the error.

More info: Scope =================================== Block Type: NaN key: NaN num: NaN values: [] Local this: ObjectBag arr: Array(2) 0: NaN 1: "rgb" length: 2

obj: {fill: Color}

Interestingly, this is shown to be in file Morphable.js, which is not loaded (I only load svn.js).

Fuzzyma commented 1 year ago

In order to animate an attribute, it has to be set in the first place. If you want to use css, you have to keep using css in the animate call. If you want to use the fill-attribute, set it at the start as well