I'm trying to get a bunch of background-position-y
values from a number of elements and minus a percentage from the pixel value and then assign that new value to each element. E.g. Minus 30% of 40px = 28px. My code below is not working as expected.
var jq = jQuery;
var icon = jq('#weather i');
jq(icon).each(function(){
var bgPosX = jq(this).css('background-position-x');
var bgPosY = jq(this).css('background-position-y');
var bgPosYNew = bgPosY - 30%;
jq(this).css({
'background-position-x' : bgPosX,
'background-position-y' : bgPosYNew
});
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…