SCSS 中的动态变量

罗约斯

您好,我想根据在我的 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;
}
米凯尔·莱格

你可以在 jQuery 中做到:

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

// else you keep the current background

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章