使用jQuery更改HTML背景图片

3
我需要更换背景图片,所以我使用了以下代码:

$('body').css({backgroundImage : 'url(images/wallpaper/'+wp+'.jpg)'});

但是,我需要使用以下属性:no-repeat fixed bottom left

如果我尝试:

$('body').css({backgroundImage : 'url(images/wallpaper/'+wp+'.jpg)  no-repeat fixed bottom left'});

"这不工作。有人能解决吗?"
4个回答

6

试试这个:

  $('body').css({background : 'url(images/wallpaper/'+wp+'.jpg)  no-repeat fixed bottom left'});

2

$('body').css({background : 'url(images/wallpaper/'+wp+'.jpg) no-repeat fixed bottom left'});

这与CSS的同名属性类似。

background是设置background-imagebackground-repeatbackground-attachmentbackground-position等的快捷方式。


1

backgroundImage更改为background


0

$('body').css({backgroundImage : 'url(images/wallpaper/'+wp+'.jpg)', backgroundRepeat : 'no-repeat', backgroundPosition : 'fixed 0 100%'});

将背景图片设置为“images/wallpaper/”文件夹下的“wp.jpg”,并且不重复,固定在页面底部。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接