简体   繁体   English

如何在后面的代码中获取 CSS class 属性

[英]How to get a CSS class property in code behind

I've a css value that I need to call from code behind.我有一个 css 值,我需要从后面的代码中调用它。 Can someone help me with that?有人可以帮我吗?

.shape.bar.progress { position: absolute} .shape.bar.progress { position:绝对}

.shape.pro { animation: left 4s} .shape.pro { animation:左 4 秒}

@keyframes left {100%{ transform: rotate(180deg);}} @keyframes left {100%{ transform: rotate(180deg);}}

I can call the.shape.pro by shape1.attributes.add(“class”, “pro”)我可以通过 shape1.attributes.add(“class”, “pro”) 调用 the.shape.pro

Now, I want to call @keyframes so that I can change the rotate value in code behind.. how to do that?现在,我想调用@keyframes 以便我可以更改后面代码中的旋转值.. 怎么做?

Thanks谢谢

You're not supposed to access a @keyframe property.您不应该访问 @keyframe 属性。

If you just want to change your angle from 0 to 180, you don't even need keyframe.如果您只想将角度从 0 更改为 180,则甚至不需要关键帧。

Just:只是:

.shape .pro { 
  transform: rotate(180deg)
}

Then for transition effect, add this to your .shape class:然后对于过渡效果,将其添加到您的.shape class:

.shape {
  transform: rotate(0);
  transition: transform 4s
}

Yes you can change something in the keyframes from Javascript if you use CSS variables rather than a specific value.是的,如果您使用 CSS 变量而不是特定值,您可以从 Javascript 更改关键帧中的某些内容。

So in your CSS you write:所以在你的 CSS 你写:

@keyframes left {100%{ transform: rotate(var(--degrees));}}

And in your Javascript you can set the variable to whatver you want: For example:在您的 Javascript 中,您可以将变量设置为您想要的任何内容:例如:

element.style.setProperty('--degrees', n + 'deg');

where element is whichever element has that animation and n is the number of degrees.其中 element 是具有 animation 的元素,n 是度数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM