Rohan Bhangui
Rohan Bhangui

Reputation: 373

How to dynamically insert css vendor prefixes using jquery

Recently I have been working with css3 and its animations. I use the following code at one point:

$(".container").css('-webkit-transform', 'translate(200px,200px)');

Now most of you are wondering why I dont just use a class to do above and toggle it.

Well the thing is I do some calculations and then obtain the 200px,200px , so I will replace the 200px,200px with a variable (I used 200px,200px as example)

Any ideas on what I can do

Upvotes: 1

Views: 571

Answers (1)

maaachine
maaachine

Reputation: 821

If I'm understanding your question, you want to use variables for the translation outlined in the above code. If you have variables like:

var x = 200, y = 200;

You should be able to insert them into the translation string by cutting it up and catenating them together. It might look like:

$(".container").css('-webkit-transform', 'translate('+x+'px,'+y+'px)');

Upvotes: 1

Related Questions