Travis build: 604
This commit is contained in:
26
README.md
26
README.md
@ -218,6 +218,7 @@ average(1, 2, 3);
|
||||
* [`detectDeviceType`](#detectdevicetype)
|
||||
* [`elementContains`](#elementcontains)
|
||||
* [`elementIsVisibleInViewport`](#elementisvisibleinviewport-)
|
||||
* [`getImages`](#getimages)
|
||||
* [`getScrollPosition`](#getscrollposition)
|
||||
* [`getStyle`](#getstyle)
|
||||
* [`hasClass`](#hasclass)
|
||||
@ -3520,6 +3521,31 @@ elementIsVisibleInViewport(el, true); // true - (partially visible)
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
### getImages
|
||||
|
||||
Fetches all images from within an element and puts them into an array
|
||||
|
||||
Use `Element.prototype.getElementsByTagName()` to fetch all `<img>` elements inside the provided element, `Array.prototype.map()` to map every `src` attribute of their respective `<img>` element, then create a `Set` to eliminate duplicates and return the array.
|
||||
|
||||
```js
|
||||
const getImages = (el, includeDuplicates = false) => {
|
||||
const images = [...el.getElementsByTagName('img')].map(img => img.getAttribute('src'));
|
||||
return includeDuplicates ? images : [...new Set(images)];
|
||||
};
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
getImages(document, true); // ['image1.jpg', 'image2.png', 'image1.png', '...']
|
||||
getImages(document, false); // ['image1.jpg', 'image2.png', '...']
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
### getScrollPosition
|
||||
|
||||
Returns the scroll position of the current page.
|
||||
|
||||
Reference in New Issue
Block a user