Reputation: 81
Is there a way to access the seperate properties for box-shadow..
e.g.
I want to pull out the value of 'blur' and 'spread' separately, and set some sliders I have based on these values.
Is there some way to access these from the shorthand 'box-shadow' property
e.g.
box-shadow-spread box-shadow-color,
ect.
I don't want to store a bunch of attributes on the node, just to track these values and setup controls.
Upvotes: 0
Views: 65
Reputation: 13334
Just use the ole pick_apart function:
function pick_apart(img_id) {
hold_res={}
ss = $('#' + img_id).css('box-shadow')
hold_res['color'] = ss.substring(ss.lastIndexOf("r"),ss.lastIndexOf(")")+1);
hold_res['offset_x'] = ss.split(' ')[3]
hold_res['offset_y'] = ss.split(' ')[4]
hold_res['blur_radius'] = ss.split(' ')[5]
hold_res['spread_radius'] = ss.split(' ')[6]
return(hold_res)
}
HTML:
<img id='my_img' src='https://pbs.twimg.com/profile_images/988775660163252226/XpgonN0X_400x400.jpg'>
CSS
img {
box-shadow: 10px 20px 30px 40px #555;
}
Usage:
pick_apart('my_img')
Result:
{
"color": "rgb(85, 85, 85)",
"offset_x": "10px",
"offset_y": "20px",
"blur_radius": "30px",
"spread_radius": "40px"
}
Upvotes: 1