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

https://github.com/ivopetkov/responsive-attributes


https://github.com/ivopetkov/responsive-attributes

Last synced: 7 months ago
JSON representation

Awesome Lists containing this project

README

          

# Responsive attributes
Make element's attributes responsive.

## Usage

Include the library.
```html

```

Add the `data-responsive-attributes` attribute to the target element.
```html


```

**Attribute format:**

EXPRESSION=>ATTRIBUTE_NAME=ATTRIBUTE_VALUE

**Expression properties:**

w - element's width

h - element's height

vw - viewport's width

vh - viewport's height

f(FUNCTION_NAME) - function to call

q(QUERY_SELECTOR) - query selector to run

## Examples

### 1. Check element's width
If the element's width is lower than 200px set attribute `data-size=small`.
```html


```

If the element's width is higher than 200px and lower than 500px set attribute `data-size=medium`.
```html


```

### 2. Check viewport's width
If viewport's width is lower than 200px set attribute `data-size=small`.
```html


```

If viewport's width is higher than 200px and lower than 500px set attribute `data-size=medium`.
```html


```

### 3. Run custom check
Call a JS function to check if the `data-size` attribute should be set.
```html

function check1(element, details) {
return details.width < 300;
}


```

### 4. Run a query selector
Run a query selector. If the result is not empty the `data-size` attribute will be set.
```html


```

### 5. Multiple rules
If the element's width is lower than 200px set attribute `data-width=small`. If the element's height is lower than 200px set attribute `data-height=small`.
```html


```

### 5. Multiple rules in multiple attributes
This is makes it easier to modify rules with JavaScript. Just specify `data-responsive-attributes="*"` and add multiple attributes starting with `data-responsive-attributes-`.

If the element's width is lower than 200px set attribute `data-width=small`. If the element's height is lower than 200px set attribute `data-height=small`.
```html


```