+95
-1
lines changedFilter options
+95
-1
lines changed Original file line number Diff line number Diff line change
@@ -202,6 +202,28 @@ The default `blank-color` is `transparent`.
202
202
- The `width` and `height` props will also apply the `width` and `height` attributes to the rendered
203
203
`<img>` tag, even if `blank` is not set.
204
204
205
+
## `srcset` support
206
+
207
+
`<b-img>` supports the
208
+
[`srcset` and `sizes` attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-srcset)
209
+
on images. The props accept either a string value, or an array of strings (the array of strings will
210
+
be converted into a single string separated by commas).
211
+
212
+
For details on usage of these attributes, refer to
213
+
[MDN's Responsive Images](https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images)
214
+
guide.
215
+
216
+
**Notes:**
217
+
218
+
- If the `blank` prop is set, then `srcset` and `sizes` props are ignored
219
+
- IE 11 does not support `srcset` and `sizes`, so ensure you have a value for the `src` prop
220
+
- Vue-loader does not support project relative URLs (asset URLs) on the `srcset` attribute. Instead
221
+
use `require(...)` to resolve the individual URL paths. Be cautious of creating a string of data
222
+
URI's longer than supported by the maximum attribute value length of the browser. If your webpack
223
+
config has a limit for the `url-loader` and you want to prevent inline data-urls, you may have to
224
+
overwrite the loader limits: `require('!!url-loader?limit=0!./assets/photo.jpg')`
225
+
- Support for `srcset` and `sizes` was added in release `2.1.0`
226
+
205
227
## Lazy loaded images
206
228
207
229
> Use our complementary `<b-img-lazy>` image component (based on `<b-img>`) to lazy load images as
@@ -288,4 +310,13 @@ removed.
288
310
To force the final image to be shown, set the `show` prop to `true`. The `show` prop supports the
289
311
Vue `.sync` modifier, and will be updated to `true` when the final image is shown.
290
312
313
+
### Lazy loaded `srcset` support
314
+
315
+
`<b-img-lazy>` supports setting the [`srcset` and `sizes`](#srcset-support) attributes on the
316
+
rendered `<img>` element. These props will only be applied to the image once it has come into view.
317
+
318
+
See [`srcset` support](#srcset-support) above for prop usage details and limitations.
319
+
320
+
Support for `srcset` and `sizes` was added in release `2.1.0`.
321
+
291
322
<!-- Component reference added automatically from component package.json -->
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
1
1
import Vue from '../../utils/vue'
2
+
import { concat } from '../../utils/array'
2
3
import { getComponentConfig } from '../../utils/config'
3
4
import { hasIntersectionObserverSupport } from '../../utils/env'
4
5
import { VBVisible } from '../../directives/visible/visible'
@@ -12,6 +13,14 @@ export const props = {
12
13
default: null,
13
14
required: true
14
15
},
16
+
srcset: {
17
+
type: [String, Array],
18
+
default: null
19
+
},
20
+
sizes: {
21
+
type: [String, Array],
22
+
default: null
23
+
},
15
24
alt: {
16
25
type: String,
17
26
default: null
@@ -109,6 +118,18 @@ export const BImgLazy = /*#__PURE__*/ Vue.extend({
109
118
},
110
119
computedHeight() {
111
120
return this.isShown ? this.height : this.blankHeight || this.height
121
+
},
122
+
computedSrcset() {
123
+
const srcset = concat(this.srcset)
124
+
.filter(Boolean)
125
+
.join(',')
126
+
return !this.blankSrc || this.isShown ? srcset : null
127
+
},
128
+
computedSizes() {
129
+
const sizes = concat(this.sizes)
130
+
.filter(Boolean)
131
+
.join(',')
132
+
return !this.blankSrc || this.isShown ? sizes : null
112
133
}
113
134
},
114
135
watch: {
@@ -173,6 +194,8 @@ export const BImgLazy = /*#__PURE__*/ Vue.extend({
173
194
blank: this.computedBlank,
174
195
width: this.computedWidth,
175
196
height: this.computedHeight,
197
+
srcset: this.computedSrcset || null,
198
+
sizes: this.computedSizes || null,
176
199
// Passthrough props
177
200
alt: this.alt,
178
201
blankColor: this.blankColor,
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
1
1
import Vue from '../../utils/vue'
2
2
import { mergeData } from 'vue-functional-data-merge'
3
+
import { concat } from '../../utils/array'
3
4
import { getComponentConfig } from '../../utils/config'
4
5
import { isString } from '../../utils/inspect'
5
6
@@ -20,6 +21,14 @@ export const props = {
20
21
type: String,
21
22
default: null
22
23
},
24
+
srcset: {
25
+
type: [String, Array],
26
+
default: null
27
+
},
28
+
sizes: {
29
+
type: [String, Array],
30
+
default: null
31
+
},
23
32
alt: {
24
33
type: String,
25
34
default: null
@@ -106,6 +115,12 @@ export const BImg = /*#__PURE__*/ Vue.extend({
106
115
let height = parseInt(props.height, 10) ? parseInt(props.height, 10) : null
107
116
let align = null
108
117
let block = props.block
118
+
let srcset = concat(props.srcset)
119
+
.filter(Boolean)
120
+
.join(',')
121
+
let sizes = concat(props.sizes)
122
+
.filter(Boolean)
123
+
.join(',')
109
124
if (props.blank) {
110
125
if (!height && Boolean(width)) {
111
126
height = width
@@ -118,6 +133,9 @@ export const BImg = /*#__PURE__*/ Vue.extend({
118
133
}
119
134
// Make a blank SVG image
120
135
src = makeBlankImgSrc(width, height, props.blankColor || 'transparent')
136
+
// Disable srcset and sizes
137
+
srcset = null
138
+
sizes = null
121
139
}
122
140
if (props.left) {
123
141
align = 'float-left'
@@ -134,7 +152,9 @@ export const BImg = /*#__PURE__*/ Vue.extend({
134
152
src: src,
135
153
alt: props.alt,
136
154
width: width ? String(width) : null,
137
-
height: height ? String(height) : null
155
+
height: height ? String(height) : null,
156
+
srcset: srcset || null,
157
+
sizes: sizes || null
138
158
},
139
159
class: {
140
160
'img-thumbnail': props.thumbnail,
Original file line number Diff line number Diff line change
@@ -55,6 +55,16 @@
55
55
{
56
56
"prop": "right",
57
57
"description": "Floats the image to the right when set"
58
+
},
59
+
{
60
+
"prop": "srcset",
61
+
"version": "2.1.0",
62
+
"description": "One or more strings separated by commas (or an array of strings), indicating possible image sources for the user agent to use"
63
+
},
64
+
{
65
+
"prop": "sizes",
66
+
"version": "2.1.0",
67
+
"description": "One or more strings separated by commas (or an array of strings), indicating a set of source sizes. Optionally used in combination with the srcset prop"
58
68
}
59
69
]
60
70
},
@@ -124,6 +134,16 @@
124
134
{
125
135
"prop": "right",
126
136
"description": "Floats the image to the right when set"
137
+
},
138
+
{
139
+
"prop": "srcset",
140
+
"version": "2.1.0",
141
+
"description": "One or more strings separated by commas (or an array of strings), indicating possible image sources for the user agent to use"
142
+
},
143
+
{
144
+
"prop": "sizes",
145
+
"version": "2.1.0",
146
+
"description": "One or more strings separated by commas (or an array of strings), indicating a set of source sizes. Optionally used in combination with the srcset prop"
127
147
}
128
148
]
129
149
}
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4