简体   繁体   English

使用js更改css的聚合方式

[英]Polymer way of changing css using js

I am from angular , react background getting started with polymer . 我来自有角度反应背景开始与聚合物

I have a polymer class lets say myClass having this template. 我有一个聚合物类让我说myClass有这个模板。

<div  id="[[x]]">

Here x is property defined in property getter. 这里x是属性getter中定义的属性。

  static get properties() {
    return {      
      x: {
        type: Number,
        value: 200
      },
}

Here if I set value of x dynamically using chrome dev tools console, like myClass.x = '5' it works fine and output will be. 这里,如果我使用chrome dev工具控制台动态设置x的值,就像myClass.x = '5'它工作正常,输出就是。

<div  id="5">

same goes true for other html attributes like 其他html属性也是如此

   <div  width="[[x]]">
   <div  height="[[x]]">

but now consider a case scenario that I want to give margin property dynamically to my div in the same way that I am doing with id, width, height how can I do it in Polymer? 但现在考虑一个案例场景,我想动态给我的div一个margin属性 ,就像我用id,width,height一样,我怎么能在Polymer中做呢?

In angular we can do this. 角度我们可以做到这一点。

<div [style.marginTop.px]="marginTop">

Let me know your thought in polmer way od doing things. 让我知道你的做法以polmer方式做事。

我明白了,可以通过做这样的事情来实现。

<div style$="margin:{{ x }}px;">

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

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