Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

198
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda