开发者

Adding class to an element using jQuery + simultaneously sending custom values of css class parameters

I don't know if this is possible but will try to explain what I need.

I want to do something like this ....

CSS class with undefined variables X,Y,Z:

.r {border-radius:Xpx;-webkit-border-radius:Ypx;-moz-border-radius:Zpx;}

Then in body:

<div id='test'></div>

Script:

$("#test").addClass("r(10,10,10)")

As you see I have a CSS class but there are no numbers. Just variables.

And I want to apply this class to element using jquery and send all variables through jquery.

Is there any way开发者_运维问答 to do this ?


Interesting idea, but unfortunately not possible to implement directly: the CSS is "compiled" instantly so such CSS is just invalid and won't be recognized.

Instead, what you can do is have such code:

$("#test").css({ "border-radius": "10px", "-webkit-border-radius": "10px", "-moz-border-radius": "10px" });

To set the CSS properties on the fly with jQuery.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜