你可以通过使用几个正则表达式来获取颜色、hshadow、vshadow、模糊、展开以及它是否是插入的。一旦你得到它,你可以简单地将它增加 2。把它们放在一起并应用到按钮上。
这是更新的 jsfiddle(使用从原始 box-shadow CSS 获得的颜色和插入值。这是它的外观(更新):
var pattern = /\d+px/g; //will match only those values with a number + px
var colorPattern = /rgb\(.+\)/; //regex to get the color
var incr = 2;
$('#btn').bind('click', function(){
var currentBoxShadowCSS = $(this).css('box-shadow');
var color = currentBoxShadowCSS.match(colorPattern)[0];
/*
That will get us the color:
rgb(255, 0, 0)
*/
var matchesArr = $(this).css('box-shadow').match(pattern);
/*
That will return ["0px", "0px", "5px", "0px"]
That s basically [h-shadow, v-shadow, blur, spread]
We are concerned with only the first 3
*/
var oldHShadow = matchesArr[0].split('px')[0];
var newHShadow = parseInt(oldHShadow, 10) + incr;
var oldVShadow = matchesArr[1].split('px')[0];
var newVShadow = parseInt(oldVShadow, 10) + incr;
var oldBlur = matchesArr[2].split('px')[0];
var newBlur = parseInt(oldBlur, 10) + incr;
//check if this was an inset shadow
var inset = currentBoxShadowCSS.indexOf('inset') > -1 ? ' inset': '';
//we got what we need, apply it
$(this).css('box-shadow', newHShadow + 'px ' + newVShadow + 'px ' + newBlur + 'px ' + color + inset);
});