【问题标题】:css() is not setting background property for body tagcss() 没有为 body 标签设置背景属性
【发布时间】:2016-02-26 09:23:35
【问题描述】:

我在我的代码中使用了这些东西,但它们都不起作用..请建议我解决此问题的任何其他方法。

// #1
if ("${actionBean.backgroundImage}" != null){
    $(document.body).css("pointer-events", "none");
    $(document.body).css("cursor", "default");
    $(document.body).css("background", "url('${actionBean.backgroundImage}') no-repeat fixed center -80px / cover !important");
} 

// #2
if ("${actionBean.backgroundImage}" != null){
    $('html, body').css("pointer-events", "none");
    $('html, body').css("cursor", "default");
    $('html, body').css("background", "url('${actionBean.backgroundImage}') no-repeat fixed center -80px / cover !important");
}

// #3
if ("${actionBean.backgroundImage}" != null){
    $("body").css("pointer-events","none");
    $("body").css("cursor","default");
    $("body").css("background", "url('${actionBean.backgroundImage}') no-repeat fixed center -80px / cover !important");
}

// #4
if ("${actionBean.backgroundImage}" != null){
    $(body).css("pointer-events", "none");
    $(body).css("cursor", "default");
    $(body).css("background", "url('${actionBean.backgroundImage}') no-repeat fixed center -80px / cover !important");
}

【问题讨论】:

  • 这是什么意思${actionBean.backgroundImage}。这是selector
  • 你的逻辑有缺陷; "${actionBean.backgroundImage}" != null永远不会false,即使值是''
  • ${actionBean.backgroundImage} ...它是一个Stripes变量...并且这里的条件不是假的...我正在使用Stripes Framework...

标签: javascript java jquery html css


【解决方案1】:

尝试使用单独的背景属性,例如:

$(body).css("background", "no-repeat fixed center -80px / cover !important");

$(body).css("background-image", "url('${actionBean.backgroundImage}')");

这必须包含在正文下方。

【讨论】:

  • 是的,它的工作原理......但是请解释一下......它是如何正确地做事的?我的代码逻辑有问题吗?
【解决方案2】:

你也可以通过为你的 body 类提供 id 来使用它......并使用它来添加 CSS

if ("${actionBean.backgroundImage}" != null){
  $("#bodyId").css("pointer-events", "none");
  $("#bodyId").css("cursor", "default");
  $("#bodyId").css("background", "url('${actionBean.backgroundImage}') no-repeat fixed center -80px / cover !important");

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-17
    • 2011-03-07
    • 2012-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多