jquery - 使用 JQuery 选择随机背景

标签 jquery html css

我的代码没有返回任何错误,只是保留了没有背景图片的叠加效果:

$(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/

相关文章:

php - 根据 Select DropDown 使用 PHP 变量

javascript - 箭头键在输入和文本区域中不起作用

html - 奇怪的 CSS 选择器 - Chrome

html - 屏幕的 100% 高度和宽度

html - 帮助创建带有 flex 标题部分的 HTML 页面

css - 使用 <a href ="#goToDiv"> 时突出显示 div

javascript - jQuery 第一次点击 show() 第二次加载视频

javascript - 在 mousemove() 事件处理程序中按下了哪个鼠标键?

javascript - 使用jquery获取json数据

html - 在位置 : Absolute continer HTML CSS 中的元素后面