Can I fetch the value of a non-standard CSS property via Javascript?

前端 未结 6 679
傲寒
傲寒 2020-11-28 12:11

I am trying to read a custom (non-standard) CSS property, set in a stylesheet (not the inline style attribute) and get its value. Take this CSS for example:

         


        
6条回答
  •  Happy的楠姐
    2020-11-28 12:59

    By reading in the Stylesheet info in IE, you CAN get these "bogus" properties, but only in IE that I'm aware of.

    var firstSS = document.styleSheets[0];
    var firstSSRule = firstSS.rules[0];
    if(typeof(firstSSRule.style.bar) != 'undefined'){
      alert('value of [foo] is: ' + firstSSRule.style.bar);
    } else {
      alert('does not have [foo] property');
    }
    

    Its ugly code, but you get the picture.

提交回复
热议问题