scss 有用的SASS mixins

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了scss 有用的SASS mixins相关的知识,希望对你有一定的参考价值。

$vendors: -webkit-, -moz-, -ms-, -o-, '';

@mixin property-vendor-prefixer($property, $value) {
  @each $vendor in $vendors {
    #{$vendor}#{$property}: $value;
  }
}

@mixin value-vendor-prefixer($property, $value) {
  @each $vendor in $vendors {
    #{$property}: #{$vendor}#{$value};
  }
}

@mixin transition($property, $duration, $timing, $delay: 0s) {
  @each $vendor in $vendors {
    #{$vendor}transition: $property $duration $timing $delay;
  }
}

@mixin animation($name, $duration, $timing, $delay, $iteration, $direction) {
  @each $vendor in $vendors {
    #{$vendor}animation: $name $duration $timing $delay $iteration $direction;
  }
}

@mixin keyframes($name) {
  @-webkit-keyframes #{$name} {
    @content;
  }

  @-moz-keyframes #{$name} {
    @content;
  }

  @-ms-keyframes #{$name} {
    @content;
  }

  @keyframes #{$name} {
    @content;
  }
}

@mixin clearfix() {
  &:before, &:after {
    content: "";
    display: table;
  }
  &:after {
    clear: both;
  }
}

@mixin triangle ($direction, $size, $color) {
  $directions: (
    bottom: top,
    top: bottom,
    left: right,
    right: left
  ); 
  
  border: solid $size transparent;
  border-#{map-get($directions, $direction)}-color: $color;
  height: 0;
  width: 0;
}

@mixin ellipsis {
  text-overflow: ellipsis;
  vertical-align: top;
  white-space: nowrap;
  overflow: hidden;
  display: inline-block;
}

@mixin noselect {
  -webkit-touch-callout: none;
  @include property-vendor-prefixer(user-select, none);
  cursor: default;
}

以上是关于scss 有用的SASS mixins的主要内容,如果未能解决你的问题,请参考以下文章

scss SASS,SCSS,mixin:PX到EM的转换

sass

scss sass_vertical-ALIGN-mixin.scss

scss 用于媒体查询的Sass mixins

scss 简单的Sass字体mixin

scss 更方便的sass mixins