An open API service indexing awesome lists of open source software.

https://github.com/cuth/dynamic-size-images

Change image src or background image path based on the size of the element
https://github.com/cuth/dynamic-size-images

Last synced: 7 months ago
JSON representation

Change image src or background image path based on the size of the element

Awesome Lists containing this project

README

          

Dynamic Size Images
===================

Use the size of the element to assign images from paths in attributes. This requires jQuery. Assign in javascript the attributes that will be used for each element width or height.

```javascript
new DynamicSizeImages('.selector', [
{
attrName: 'data-src-small',
size: 200
},
{
attrName: 'data-src-medium',
size: 350
},
{
attrName: 'data-src-large',
size: 500
},
{
attrName: 'data-src-xlarge'
}
], {
measure: 'width', // either 'width' or 'height'
operator: '<=', // '<', '>', '<=', or '>='
debounceTime: 150, // time it waits after browser resize
checkOnWinLoad: false // measure sizes after window onload
});
```

Helpful CSS
```css
img {
visibility: hidden;
}
img[src] {
visibility: visible;
}
```

jQuery Plugin
-------------
For extra convenience use this as a jQuery plugin. The plugin method returns a DynamicSizeImages instance rather than a jQuery object (chaining is not supported).
```js
var profile = $('.selector').DynamicSizeImages([
{
attrName: 'data-src-large',
size: 500
},
{
attrName: 'data-src-xlarge'
}
]);
```