| OLD | NEW |
| (Empty) |
| 1 <!-- | |
| 2 @license | |
| 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | |
| 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt | |
| 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | |
| 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt | |
| 7 Code distributed by Google as part of the polymer project is also | |
| 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt | |
| 9 --><html><head><link rel="import" href="../polymer/polymer.html"> | |
| 10 <link rel="import" href="../iron-flex-layout/iron-flex-layout.html"> | |
| 11 | |
| 12 <!-- | |
| 13 `iron-image` is an element for displaying an image that provides useful sizing a
nd | |
| 14 preloading options not found on the standard `<img>` tag. | |
| 15 | |
| 16 The `sizing` option allows the image to be either cropped (`cover`) or | |
| 17 letterboxed (`contain`) to fill a fixed user-size placed on the element. | |
| 18 | |
| 19 The `preload` option prevents the browser from rendering the image until the | |
| 20 image is fully loaded. In the interim, either the element's CSS `background-col
or` | |
| 21 can be be used as the placeholder, or the `placeholder` property can be | |
| 22 set to a URL (preferably a data-URI, for instant rendering) for an | |
| 23 placeholder image. | |
| 24 | |
| 25 The `fade` option (only valid when `preload` is set) will cause the placeholder | |
| 26 image/color to be faded out once the image is rendered. | |
| 27 | |
| 28 Examples: | |
| 29 | |
| 30 Basically identical to `<img src="...">` tag: | |
| 31 | |
| 32 <iron-image src="http://lorempixel.com/400/400"></iron-image> | |
| 33 | |
| 34 Will letterbox the image to fit: | |
| 35 | |
| 36 <iron-image style="width:400px; height:400px;" sizing="contain" | |
| 37 src="http://lorempixel.com/600/400"></iron-image> | |
| 38 | |
| 39 Will crop the image to fit: | |
| 40 | |
| 41 <iron-image style="width:400px; height:400px;" sizing="cover" | |
| 42 src="http://lorempixel.com/600/400"></iron-image> | |
| 43 | |
| 44 Will show light-gray background until the image loads: | |
| 45 | |
| 46 <iron-image style="width:400px; height:400px; background-color: lightgray;" | |
| 47 sizing="cover" preload src="http://lorempixel.com/600/400"></iron-image> | |
| 48 | |
| 49 Will show a base-64 encoded placeholder image until the image loads: | |
| 50 | |
| 51 <iron-image style="width:400px; height:400px;" placeholder="data:image/gif;b
ase64,..." | |
| 52 sizing="cover" preload src="http://lorempixel.com/600/400"></iron-image> | |
| 53 | |
| 54 Will fade the light-gray background out once the image is loaded: | |
| 55 | |
| 56 <iron-image style="width:400px; height:400px; background-color: lightgray;" | |
| 57 sizing="cover" preload fade src="http://lorempixel.com/600/400"></iron-ima
ge> | |
| 58 | |
| 59 Custom property | Description | Default | |
| 60 ----------------|-------------|---------- | |
| 61 `--iron-image-placeholder` | Mixin applied to #placeholder | `{}` | |
| 62 `--iron-image-width` | Sets the width of the wrapped image | `auto` | |
| 63 `--iron-image-height` | Sets the height of the wrapped image | `auto` | |
| 64 | |
| 65 @group Iron Elements | |
| 66 @element iron-image | |
| 67 @demo demo/index.html | |
| 68 --> | |
| 69 | |
| 70 </head><body><dom-module id="iron-image"> | |
| 71 <template> | |
| 72 <style> | |
| 73 :host { | |
| 74 display: inline-block; | |
| 75 overflow: hidden; | |
| 76 position: relative; | |
| 77 } | |
| 78 | |
| 79 #sizedImgDiv { | |
| 80 @apply(--layout-fit); | |
| 81 | |
| 82 display: none; | |
| 83 } | |
| 84 | |
| 85 #img { | |
| 86 display: block; | |
| 87 width: var(--iron-image-width, auto); | |
| 88 height: var(--iron-image-height, auto); | |
| 89 } | |
| 90 | |
| 91 :host([sizing]) #sizedImgDiv { | |
| 92 display: block; | |
| 93 } | |
| 94 | |
| 95 :host([sizing]) #img { | |
| 96 display: none; | |
| 97 } | |
| 98 | |
| 99 #placeholder { | |
| 100 @apply(--layout-fit); | |
| 101 | |
| 102 background-color: inherit; | |
| 103 opacity: 1; | |
| 104 | |
| 105 @apply(--iron-image-placeholder); | |
| 106 } | |
| 107 | |
| 108 #placeholder.faded-out { | |
| 109 transition: opacity 0.5s linear; | |
| 110 opacity: 0; | |
| 111 } | |
| 112 </style> | |
| 113 | |
| 114 <div id="sizedImgDiv" role="img" hidden$="[[_computeImgDivHidden(sizing)]]"
aria-hidden$="[[_computeImgDivARIAHidden(alt)]]" aria-label$="[[_computeImgDivAR
IALabel(alt, src)]]"></div> | |
| 115 <img id="img" alt$="[[alt]]" hidden$="[[_computeImgHidden(sizing)]]"> | |
| 116 <div id="placeholder" hidden$="[[_computePlaceholderHidden(preload, fade, lo
ading, loaded)]]" class$="[[_computePlaceholderClassName(preload, fade, loading,
loaded)]]"></div> | |
| 117 </template> | |
| 118 | |
| 119 </dom-module> | |
| 120 <script src="iron-image-extracted.js"></script></body></html> | |
| OLD | NEW |