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
  • 相关阅读:
    后续阶段第二天
    后续阶段第一天
    冲刺第五天
    冲刺第四天
    冲刺第三天
    冲刺第二天
    第二阶段-冲刺第一天
    第一阶段项目总结
    冲刺(7)
    团队开发冲刺第一阶段_6
  • 原文地址:https://www.cnblogs.com/Answer1215/p/8930987.html
Copyright © 2011-2022 走看看