首页 > 编程语言 > 详细

[SCSS] Convert SCSS Variable Arguments to JavaScript

时间:2018-04-24 16:09:20      阅读:188      评论:0      收藏:0      [点我收藏+]

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

 

[SCSS] Convert SCSS Variable Arguments to JavaScript

原文:https://www.cnblogs.com/Answer1215/p/8930987.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!