Add additional box-shadow to an element where existing shadow is unknown

后端 未结 4 1316
庸人自扰
庸人自扰 2021-02-14 05:17

I\'m assuming the answer to this question is that it\'s impossible, but I\'m asking anyway in the hopes that someone knows of a clever workaround.

Let\'s say I have the

4条回答
  •  别那么骄傲
    2021-02-14 05:34

    One way would be to determine the current box-shadow, superimpose the required parts to it and apply it back (not sure if it'll be worth the trouble but..).

    window.getComputedStyle(element).boxShadow

    will give you a string formatted like:

    - for example: rgb(102, 102, 102) 5px 5px 5px 0px

    Once you have the above string in a variable:

    1. split it using space character - s = s.split(' ');
    2. take the last four parts
    3. replace or keep individual values as required in the array
    4. join the array using space - s = s.join(' ');
    5. apply it back to the element - elem.style.boxShadow = s;

    NOTE: This works in ff and chrome (since the returned string format is the same). But i think this is too much of an overkill to actually try in a production version. Moreover, it'll take even more work to superimpose styles from a class you've written in your css.

提交回复
热议问题