Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
Animating distantLight filter with svg.js

I am attempting to create a simple SVG animation using SVG.js. My desired result would be equivalent to:

<filter">
  <feDiffuseLighting result="diffOut" in="SourceGraphic" diffuseConstant="1.2"
    lighting-color="white">
    <feDistantLight azimuth="240" elevation="100">
        <animate attributeName="elevation"
            values="100; 20" dur="7s"
         />
     </feDistantLight>
  </feDiffuseLighting>
  <feComposite in="SourceGraphic" in2="diffOut" operator="arithmetic"
     result="diffPointOut" k1="1" k2="0" k3="0" k4="0" />
</filter>

As of now I was able to replicate everything but the animation via using svg.js and svg.filter.js:

foreground.filterWith(function (filter) {
    diff = filter.diffuseLighting().attr({
        'lighting-color': 'white',
        'diffuseConstant': 1.2
    });
    dLight = SVG('<feDistantLight azimuth="240" elevation="100"/>');
    diff.add(dLight);

    filter.composite(filter.source, diff)
        .attr({
            operator: 'arithmetic',
            k1: 1, k2: 0, k3: 0, k4: 0
        });
});

This snippet of code generates in resulting DOM the exact same filter without the animation To add an animation I've attempted to use:

 dLight.animate(7000, 0, 'now').attr({ "elevation": 20 });

But it causes an error declaring, that 'dLight' has no function named 'animate'. If I try to create my own svg.js animation runner and pass dLight to it, it would cause a similar error, declaring, that it doesn't have a '_prepareRunner' function.

On the other hand I can animate any attribute of 'diff' - the diffuseLight filter just fine. Which means my trouble is probably caused by a way I used to create distantLightFilter via SVG(...) method, but I found no other method to create it, since as according to last post here: https://github.com/svgdotjs/svg.filter.js/issues/18 the svg.filter.js does not provide a constructor for it anymore.
I am looking for help in either adding an animation to result of SVG(...) call or creating a distantLight filter in more proper animatable way.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

According to this comment there is actually a constructor for a distantLight (and other types of light) filter inside the diffuseLight filter class. When initialised via those constructors distantLight filter does support animations properly. All credit for this answer goes to Fuzzyma.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!