开发者

Add a space in a javascript line

开发者 https://www.devze.com 2023-03-09 07:20 出处:网络
I have this line of code: var bgposh = \"-37\"; $(element).find(\'.toggle_box\').css({\'-webkit-transition\': \'background-position 0.2s linear\', \'background-position\': \'147px \"+ bgposh +\"px\

I have this line of code:

var bgposh = "-37";


$(element).find('.toggle_box').css({'-webkit-transition': 'background-position 0.2s linear', 'background-position': '147px "+ bgposh +"px'});

but the background position does not get set. I think it is because there is no space between px 开发者_运维问答and bgposh. How can I add one? I tried + + but that does not seem to work.

Thanks a lot :)


Little syntax error i think with your bgposh variable

$(element).find('.toggle_box').css(
   {'-webkit-transition': 'background-position 0.2s linear', 
    'background-position': '147px '+ bgposh +'px'
   });


No, it is because with this code you have set background-position to 147px "+ bgposh +"px.

You have wrong quotes. The correct version looks like this (notice different quotes):

$(element).find('.toggle_box').css({
    '-webkit-transition': 'background-position 0.2s linear',
    'background-position': '147px ' + bgposh + 'px'
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号