summaryrefslogtreecommitdiffstats
path: root/devtools/docs/user/page_inspector/how_to/work_with_animations/animation_inspector_example_colon__web_animations_api/index.rst
blob: 6d6f2cb045265c39704e8854f0b283b2fa0b4a54 (plain)
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
114
115
116
117
===============================================
Animation inspector example: Web Animations API
===============================================

Firefox Logo Animation
**********************

Example animation using the `Web Animations API <https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API>`_.


HTML Content
------------

.. code-block:: html

  <div class="channel">
    <img src="developer.png" id="icon"/>
    <span id="note">Firefox Developer Edition</span>
  </div>


CSS Content
-----------

.. code-block:: css

  .channel {
    padding: 2em;
    margin: 0.5em;
    box-shadow: 1px 1px 5px #808080;
    margin: 1.5em;
  }

  .channel > * {
    vertical-align: middle;
    line-height: normal;
  }

  #icon {
    width: 50px;
    height: 50px;
    filter: grayscale(100%);
  }

  #note {
    margin-left: 1em;
    font: 1.5em "Open Sans",Arial,sans-serif;
    overflow: hidden;
    white-space: nowrap;
    display: inline-block;
    opacity: 0;
    width: 0;
  }


.. _page-inspector-work-with-animations-web-example-js-content:

JavaScript Content
------------------

.. code-block:: JavaScript

  var iconKeyframeSet = [
    { transform: 'scale(1)', filter: 'grayscale(100%)'},
    { filter:  'grayscale(100%)', offset: 0.333},
    { transform: 'scale(1.5)', offset: 0.666 },
    { transform: 'scale(1.5)', filter: 'grayscale(0%)'}
  ];

  var noteKeyframeSet = [
    { opacity: '0', width: '0'},
    { opacity: '1', width: '300px'}
  ];

  var iconKeyframeOptions = {
    duration: 750,
    fill: 'forwards',
    easing: 'ease-in',
    endDelay: 100
  }

  var noteKeyframeOptions = {
    duration: 500,
    fill: 'forwards',
    easing: 'ease-out',
    delay: 150
  }

  var icon = document.getElementById("icon");
  var note = document.getElementById("note");

  var iconAnimation = icon.animate(iconKeyframeSet, iconKeyframeOptions);
  var noteAnimation = note.animate(noteKeyframeSet, noteKeyframeOptions);

  iconAnimation.pause();
  noteAnimation.pause();

  var firstTime = true;

  function animateChannel(e) {
   if (e.button != 0) {
   return;
   }
    if (e.target.id != "icon") {
      return;
    }
    if (firstTime) {
      iconAnimation.play();
      noteAnimation.play();
      firstTime = false;
    } else {
      iconAnimation.reverse();
      noteAnimation.reverse();
    }
  }

  document.addEventListener("click", animateChannel);