How change content value of pseudo :before element by Javascript

后端 未结 8 859
闹比i
闹比i 2020-11-29 23:34

I have the grap constructured by CSS, which is dynamically changes by JS. I show graph max value by pseudo element as:

.graph:before {
    content:\"\"; //va         


        
8条回答
  •  被撕碎了的回忆
    2020-11-30 00:28

    You can use CSS variable

    :root {
      --h: 100px;
    }
    
    .elem:after {
      top: var(--h);
    }
    
    let y = 10;
    
    document.documentElement.style.setProperty('--h', y + 'px')
    

    https://codepen.io/Gorbulin/pen/odVQVL

提交回复
热议问题