change CSS keyframe via jQuery

Asked

Viewed 153 times

0

I’m trying to change one keyframe CSS, actually do an update, but I’m not getting concatenar variables CSS à javaScript.

To ideia, actually, it’s not even changing. But yes, inserir no final do keyframe the lines created

How to fix this?

       tMin = 0;
       tMax = 20;
       tempoImagens = 20;

       $("@keyframe animacao").css({        

          tMin + "% : margin-left:-" + tempoImagens + "%",
          tMax + "% : margin-left:-" + tempoImagens + "%"   

       });

You are giving error in concatenation.

   tMin + "% : 
  • Have you already tested this? Pq the jQuery returns error by placing an arroba (@) in the selector: $("@animation keyframe")

  • Yes, it was a mistake. But it replaces it for $("<style>@keyframe played"). css(, and the error passed, but the keyframe is not being populated.

  • Instead of doing . css({ various lines }), try in the simple way . css('style','value')

  • It is not possible because I do not know what values will be used or how many images will be placed. I just need to figure out a way to make that keyframe work. I mean, popular it,

  • Good, but in this multi-line format of . css() you won’t be able to concatenate on the left side of :...

  • Actually I already got it, no error in the browser. But the keyframe is not being populated

Show 1 more comment

1 answer

0

This is because you are creating a variable and setting its initial value as an integer. So when you try to concatenate, the interpreter "thinks" that you are trying to add up, then it gives error, like: "HOW TO ADD 20 + 'text'".

Instead of putting this:

tMin = 0;
tMax = 20;
tempoImagens = 20;

Put this on:

tMin = "0";
tMax = "20";
tempoImagens = "20";

Or you can also convert the value from integer to text before trying concatenation!

  • I believe that this does not happen because when there is a string in the middle of the statement, the interpreter assumes as concatenation. Ex: ""+ 5 + 10 == "510";

Browser other questions tagged

You are not signed in. Login or sign up in order to post.