0

I need to find the actual box-shadow element values of a css style rule that is written by the server. More specifically I need to know if the element has a visible shadow or not. which means, there may be a case where the shadow rule is not "none" but not displayed because the rgba value has 0 opacity, or the blur is 0 and the spread is negative.

any ideas?

  • With jQuery: `$(element).css('box-shadow');` – ssc-hrep3 Jun 21 '16 at 07:08
  • this is not enough. I need to determine whether any box-shadow is rendered/displayed, in all the different edge cases. the fact that there's a box shadow property doesn't mean anything if the opacity is 0 for example. – Ohad Milchgrub Jun 21 '16 at 07:14
  • You'll get back a string with the box-shadow properties. You can parse it and find out if it is visible according to your rules. I don't think there is another way to determine the visibility of a box-shadow – ssc-hrep3 Jun 21 '16 at 07:18
  • It is also pretty similar to this question: http://stackoverflow.com/questions/2683260/jquery-getting-text-shadow-variabile – ssc-hrep3 Jun 21 '16 at 07:19

1 Answers1

0

Using both .css() and .match() methods you can easily get text-shadow value of the element :

var text_shadow = $('div').css('text-shadow').match(/(-?\d+px)|(rgb\(.+\))|(rgba\(.+\))/g);


Here is a working JSFiddle with what you need. But you must know that :

For some properties, using negative lengths is a syntax error, but for some properties, negative lengths are allowed.

tektiv
  • 14,010
  • 5
  • 61
  • 70