我的代码没有返回任何错误,只是保留了没有背景图片的叠加效果:
$(function() {
var totalCount = 8;
var bg = Math.ceil(Math.random() * totalCount);
$("html").css({
"background": "linear-gradient(to bottom, rgba(0, 0, 0, 0.4) 0%, rgba(0, 0, 0, .8) 100%), url(../img/bg0"+bg.toString()+".png) no-repeat center center fixed"
});
});
最佳答案
$("html").css({"background": "linear-gradient(to bottom, rgba(0, 0, 0, 0.4) 0%, rgba(0, 0, 0, .8) 100%), url('../img/bg0"+bg.toString()+".png') no-repeat center center fixed"});
你应该有 url('../img/bg0"+bg.toString()+".png')
即 url 内的路径应该在单引号中
关于jquery - 使用 JQuery 选择随机背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29445724/