开发者

Add a space in a javascript line

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜