zoukankan      html  css  js  c++  java
  • [SCSS] Convert SCSS Variable Arguments to JavaScript

    We will learn how to convert variable arguments by using rest operator in JavaScript.

    .sass-btn {
      color: #fff;
      background-color: #0069d9;
      margin: 5px;
      @include button-size();
      @include box-shadow(0px 4px 5px #666, 2px 6px 10px #999);
    }
    
    @mixin box-shadow($shadows...) {
      -moz-box-shadow: $shadows;
      -webkit-box-shadow: $shadows;
      box-shadow: $shadows;
    }

    Scss "$shadows..." the same as "...shadows" in Javascript.

    export const boxShadow = (...shadows) => `
      -moz-box-shadow: ${shadows};
      -webkit-box-shadow: ${shadows};
      box-shadow: ${shadows};
    `

    interesting thing is ...shadows in Javascript is an Array, but if we put into ${}, then it conver to a string:

    const shadows = ['red', 'blue'];
    
    console.log(`${shadows}`); // red, blue
  • 相关阅读:
    hdu-4283 You Are the One 区间dp,
    HDU
    HDU
    HDU
    SPOJ
    UESTC
    CodeForces
    HDU
    Git中文书籍
    zeng studio的项目窗口PHP Explorer
  • 原文地址:https://www.cnblogs.com/Answer1215/p/8930987.html
Copyright © 2011-2022 走看看