File: keyframes.md

package info (click to toggle)
node-stylus 0.48.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,196 kB
  • ctags: 766
  • sloc: makefile: 38
file content (113 lines) | stat: -rw-r--r-- 2,032 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
---
layout: default
permalink: docs/keyframes.html
---

# @keyframes

Stylus supports `@keyframes` both with curly braces or without them, you can also use interpolation both in names or steps of @keyframes:

    $keyframe-name = pulse
    @keyframes {$keyframe-name}
      for i in 0..10
        {10% * i}
          opacity (i/10)

Yielding (expanded prefixes ommited):

    @keyframes pulse {
      0% {
        opacity: 0;
      }
      20% {
        opacity: 0.2;
      }
      40% {
        opacity: 0.4;
      }
      60% {
        opacity: 0.6;
      }
      80% {
        opacity: 0.8;
      }
      100% {
        opacity: 1;
      }
    }

## Expansion

By using `@keyframes`, your rules are automatically expanded to the vendor prefixes defined by the `vendors` variable (default: `moz webkit o ms official`). This means we can alter it at any time for the expansion to take effect immediately. 

**Note that expansion of `@keyframes` to the prefixed at-rules would be removed from the Stylus 1.0 when we'd get to it**
 
For example, consider the following:

    @keyframes foo {
      from {
        color: black
      }
      to {
        color: white
      }
    }

This expands to our three default vendors, and the official syntax:

    @-moz-keyframes foo {
      from {
        color: #000;
      }
      to {
        color: #fff;
      }
    }
    @-webkit-keyframes foo {
      from {
        color: #000;
      }
      to {
        color: #fff;
      }
    }
    @-o-keyframes foo {
      from {
        color: #000;
      }
      to {
        color: #fff;
      }
    }
    @keyframes foo {
      from {
        color: #000;
      }
      to {
        color: #fff;
      }
    }

If we wanted to limit to the official syntax only, simply alter `vendors`:

    vendors = official

    @keyframes foo {
      from {
        color: black
      }
      to {
        color: white
      }
    }

Yielding:

    @keyframes foo {
      from {
        color: #000;
      }
      to {
        color: #fff;
      }
    }