| <!DOCTYPE html> |
| <meta charset="UTF-8"> |
| <style> |
| div.wrapper { |
| border: 10px solid black; |
| width: 100px; |
| height: 100px; |
| display: inline-block; |
| margin-bottom: 10px; |
| } |
| .target { |
| -webkit-mask-position: top, bottom; |
| -webkit-mask-size: 100px 50px; |
| -webkit-mask-repeat: no-repeat; |
| background-color: blue; |
| height: 100%; |
| } |
| div.wrapper:nth-child(2n) { |
| border-color: green; |
| } |
| </style> |
| <body> |
| <template id="target-template"> |
| <div class="wrapper"> |
| <div class="target"></div> |
| </div> |
| </template> |
| <script src="resources/interpolation-test.js"></script> |
| <script> |
| // Image to image |
| var from = 'url(../resources/stripes-100.png)'; |
| var to = 'url(../resources/blue-100.png)'; |
| assertInterpolation({ |
| property: '-webkit-mask-image', |
| from: from, |
| to: to, |
| }, [ |
| {at: -0.3, is: from}, |
| {at: 0, is: from}, |
| {at: 0.3, is: '-webkit-cross-fade(' + from + ', ' + to + ', 0.3)'}, |
| {at: 0.6, is: '-webkit-cross-fade(' + from + ', ' + to + ', 0.6)'}, |
| {at: 1, is: to}, |
| {at: 1.5, is: to}, |
| ]); |
| |
| // Image to gradient |
| from = 'url(../resources/stripes-100.png)'; |
| to = 'linear-gradient(45deg, blue, transparent)'; |
| assertInterpolation({ |
| property: '-webkit-mask-image', |
| from: from, |
| to: to, |
| }, [ |
| {at: -0.3, is: from}, |
| {at: 0, is: from}, |
| {at: 0.3, is: '-webkit-cross-fade(' + from + ', ' + to + ', 0.3)'}, |
| {at: 0.6, is: '-webkit-cross-fade(' + from + ', ' + to + ', 0.6)'}, |
| {at: 1, is: to}, |
| {at: 1.5, is: to}, |
| ]); |
| |
| // Gradient to gradient |
| from = 'linear-gradient(-45deg, blue, transparent)'; |
| to = 'linear-gradient(45deg, blue, transparent)'; |
| assertInterpolation({ |
| property: '-webkit-mask-image', |
| from: from, |
| to: to, |
| }, [ |
| {at: -0.3, is: from}, |
| {at: 0, is: from}, |
| {at: 0.3, is: '-webkit-cross-fade(' + from + ', ' + to + ', 0.3)'}, |
| {at: 0.6, is: '-webkit-cross-fade(' + from + ', ' + to + ', 0.6)'}, |
| {at: 1, is: to}, |
| {at: 1.5, is: to}, |
| ]); |
| |
| // Keyword to image |
| from = 'none'; |
| to = 'url(../resources/blue-100.png)'; |
| assertInterpolation({ |
| property: '-webkit-mask-image', |
| from: from, |
| to: to, |
| }, [ |
| {at: -0.3, is: from}, |
| {at: 0, is: from}, |
| {at: 0.3, is: from}, |
| {at: 0.6, is: to}, |
| {at: 1, is: to}, |
| {at: 1.5, is: to}, |
| ]); |
| |
| // Multiple to multiple |
| var fromA = 'url(../resources/stripes-100.png)'; |
| var fromB = 'linear-gradient(-45deg, blue, transparent)'; |
| var toA = 'url(../resources/blue-100.png)'; |
| var toB = 'url(../resources/stripes-100.png)'; |
| from = fromA + ', ' + fromB; |
| to = toA + ', ' + toB; |
| assertInterpolation({ |
| property: '-webkit-mask-image', |
| from: from, |
| to: to, |
| }, [ |
| // The interpolation of different numbers of -webkit-mask-images looks a bit strange here. |
| // Animating -webkit-mask-image is not specified to be possible however we do it for backwards compatibility. |
| // With this in mind we kept the implementation simple at the expense of this corner case because there is |
| // no official specification to support. |
| {at: -0.3, is: from}, |
| {at: 0, is: from}, |
| {at: 0.3, is: '-webkit-cross-fade(' + fromA + ', ' + toA + ', 0.3), -webkit-cross-fade(' + fromB + ', ' + toB + ', 0.3)'}, |
| {at: 0.6, is: '-webkit-cross-fade(' + fromA + ', ' + toA + ', 0.6), -webkit-cross-fade(' + fromB + ', ' + toB + ', 0.6)'}, |
| {at: 1, is: to}, |
| {at: 1.5, is: to}, |
| ]); |
| |
| // Single to multiple |
| from = 'url(../resources/blue-100.png)'; |
| var toA = 'url(../resources/stripes-100.png)'; |
| var toB = 'url(../resources/blue-100.png)'; |
| to = toA + ', ' + toB; |
| assertInterpolation({ |
| property: '-webkit-mask-image', |
| from: from, |
| to: to, |
| }, [ |
| {at: -0.3, is: from + ', ' + from}, |
| {at: 0, is: from}, |
| {at: 0.3, is: '-webkit-cross-fade(' + from + ', ' + toA + ', 0.3), -webkit-cross-fade(' + from + ', ' + toB + ', 0.3)'}, |
| {at: 0.6, is: '-webkit-cross-fade(' + from + ', ' + toA + ', 0.6), -webkit-cross-fade(' + from + ', ' + toB + ', 0.6)'}, |
| {at: 1, is: to}, |
| {at: 1.5, is: to}, |
| ]); |
| |
| // Multiple mismatched types |
| from = 'url(../resources/blue-100.png), none'; |
| to = 'url(../resources/stripes-100.png), url(../resources/blue-100.png)'; |
| assertInterpolation({ |
| property: '-webkit-mask-image', |
| from: from, |
| to: to, |
| }, [ |
| {at: -0.3, is: from}, |
| {at: 0, is: from}, |
| {at: 0.3, is: from}, |
| {at: 0.6, is: to}, |
| {at: 1, is: to}, |
| {at: 1.5, is: to}, |
| ]); |
| </script> |
| </body> |