1

您好,我想根据 Application.js 中的变量设置 url 动态。如果变量为真,则 URL 的路径应如下所示:

"https:/asite/resources/mybackground.jpg"

否则,它将直接从应用程序的资源文件夹中获取,如下所示:

"/resources/mybackground.jpg"

所以我需要在url中附加变量。问题是该变量是在我的Application.js文件中找到的,而不是在另一个 scss 文件中。

我怎样才能做到这一点?

请在下面找到我的css代码:

.myviewport::after {
  background: url("/resources/mybackground.jpg") no-repeat;
  position: absolute;
  z-index: -1;
}
4

1 回答 1

0

你可以在 jQuery 中做到这一点:

if(need_change) { 
    $('.myviewport').css('background', 'url("the other URL")') 
}

// else you keep the current background
于 2019-08-05T13:53:01.407 回答