Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you change CSS3 animation keyframe attributes inline (i.e. in the HTML style attribute)?

Tags:

Is it possible to change the animation keyframe attributes by making inline adjustments.

Take for example

@-moz-keyframes slidein {     from {         width: 10%;     }      to {         width:50%;     } } 

Would it be possible to change the width attribute in the 'to' portion of the keyframe, by doing something like

<div id="someID" style="change keyframe here"> 

For the time being I am just creating an entire style sheet dynamically on the page in order to customize the keyframes.

This method works, however I would much rather adjust the attributes inline for simplicity.

like image 207
Koop Avatar asked Jun 28 '11 16:06

Koop


People also ask

Can you do inline CSS animations?

Yes, we can.

Does CSS3 use keyframe animation?

You can change as many CSS properties you want, as many times as you want. To use CSS animation, you must first specify some keyframes for the animation.

What is CSS keyframe animation?

Definition and Usage. The @keyframes rule specifies the animation code. The animation is created by gradually changing from one set of CSS styles to another. During the animation, you can change the set of CSS styles many times.

Can you use keyframes in CSS?

The @keyframes CSS at-rule controls the intermediate steps in a CSS animation sequence by defining styles for keyframes (or waypoints) along the animation sequence. This gives more control over the intermediate steps of the animation sequence than transitions.


1 Answers

Hey so lets think a little different... You may not be able to do this...

<div id="someID" style="change keyframe here"> 

but think of doing it like this...

<script> var createdStyleTag = document.createElement("style"); createdStyleTag.textContent = "@-*whatevaVendor*-keyframes someAnimationName{"+     "from { width: **SOMETHING YOU DECLARE THROUGH JS**; }"+     "to{ width: 10%; }"+ "}";  document.body.appendChild(createdStyleTag); </script> 

This is pretty open to whatever you want to do... you would always have the classes you will put on elements but sometimes we dont want to constantly have the same "from" and "to" so this can be one way to do this... basically you dynamically create a style element put whatever string that will end up being the needed style text and then append it to the body... works pretty good... used it in my own framework... I don't do it exactly like this but I wrote it out like this for visibility... reason why this works in a good way is cause a lot of my DOM is created dynamically as well so it may make more sense in that implementation...

Nothing is impossible... just think outside the div

like image 97
Delmarc Eric Rosario Avatar answered Sep 22 '22 21:09

Delmarc Eric Rosario