[英]Jquery not adding an background image to div
I have a function that is adding a background-image to my div. 我有一个功能,将背景图像添加到我的div。 But its not showing.
但它没有表现出来。
this is my function 这是我的功能
var totalCount = 6;
function changeBackground()
{
var num = Math.ceil( Math.random() * totalCount );
backgroundUrl = '/background/test2/'+num+'.jpg';
$('#background').css('background-image, url(' +backgroundUrl+ ')');
}
changeBackground();
The image changes everytime that the the page gets refreshed. 每次刷新页面时图像都会更改。 I know that part is working because if i change
我知道那部分是有效的,因为如果我改变了
$('#background').css('background-image, url(' +backgroundUrl+ ')');
to 至
document.body.parentNode.style.backgroundImage = 'url(background/test2/'+num+'.jpg)';
it shows me the image like i wanted. 它向我显示了我想要的图像。 But on the html tag.
但是在html标签上。 I want it on the div, so i can fade it in with jQuery.
我希望它在div上,所以我可以用jQuery淡化它。
here is my CSS 这是我的CSS
#background {
width:100% !important;
height:100% !important;
background-repeat:no-repeat;
background-position:center center;
background-attachment:fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
i don't get any error's in the console and when i look up the css nothing is added in the css. 我没有在控制台中得到任何错误,当我查找css时,css中没有添加任何内容。 How can i now what is wrong?
我现在该怎么办? So in the future i can for myself what the problem is.
所以在未来我可以为自己解决问题所在。
Change 更改
$('#background').css('background-image, url(' +backgroundUrl+ ')');
To 至
$('#background').css('background-image', 'url(' +backgroundUrl+ ')');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.