简体   繁体   English

如何使用Sass mixin过渡仅应用过渡延迟?

[英]How to use Sass mixin transition for applying transition-delay only?

As I keep continue on learning front-end developing and practicing Sass with optimizing my CSS code I got stuck again in another case. 在继续学习前端开发和练习Sass以及优化CSS代码的过程中,我又陷入了另一种情况。

After doing research and tutorials on the internet I have set up in Sass as global mixin named ' transition '. 在互联网上进行了研究和辅导后,我在Sass设置了名为“ transition ”的全局混合。 The code looks like this: 代码如下:

@mixin transition($args...) {
  -moz-transition: $args;
  -ms-transition: $args;
  -o-transition: $args;
  -webkit-transition: $args;
  transition: $args;
}

Now, I want to apply only transition-delay for my span pseudo-elements (::before and ::after). 现在,我只想对我的span伪元素(:: before和:: after)应用transition-delay Default CSS looks like this: 默认CSS如下所示:

span::before, span::after {
  transition-delay: 0.5s, 0;
}

So there is my question. 所以这是我的问题。 Is it possible to use my this definied mixin ' transition ' to pass only transition-delay as arguments? 是否可以用我这个definied混入“ 过渡 ”只传递过渡延迟参数?

I have tried: 我努力了:

@include transition(delay: .5, 0s);

but this will not work. 但这是行不通的。 I have tried to find solution in Sass documentation and find some tutorial online, no luck. 我试图在Sass文档中找到解决方案,并在线找到一些教程,但是不走运。 No idea how to define properly my problem to search for the solution. 不知道如何正确定义我的问题以寻找解决方案。

Anyone can please advice me? 任何人都可以建议我吗?

You could use an approach in which you pass the property name as an argument to the mixin 您可以使用一种方法,将属性名称作为参数传递给mixin

@mixin transition($prop, $values...) {
  -moz-#{$prop}: $values;
  -ms-#{$prop}: $values;
  -o-#{$prop}: $values;
  -webkit-#{$prop}: $values;
  $prop: $values;
}

div {
  @include transition(transition, color 1s, background-color 1s, border-color 1s);
  /* transition shorthand property can animate multiple CSS properties */
}

p {
  @include transition(transition-delay, 0.5s)
}

Which gives compiles to the following CSS 可以编译以下CSS

div {
  -moz-transition: color 1s, background-color 1s, border-color 1s;
  -ms-transition: color 1s, background-color 1s, border-color 1s;
  -o-transition: color 1s, background-color 1s, border-color 1s;
  -webkit-transition: color 1s, background-color 1s, border-color 1s; }

p {
  -moz-transition-delay: 0.5s;
  -ms-transition-delay: 0.5s;
  -o-transition-delay: 0.5s;
  -webkit-transition-delay: 0.5s; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM