|
1 |
| -# CSS Element Queries |
| 1 | +# CSS Resize Sensor |
2 | 2 |
|
| 3 | +## Warning |
3 | 4 |
|
4 |
| -[](https://gitter.im/marcj/css-element-queries?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) |
| 5 | +This version is a quick-fixed version of [marcj's `css-element-queries`](https://github.com/marcj/css-element-queries) that only exports the ResizeSensor module. |
5 | 6 |
|
6 |
| -Element Queries is a polyfill adding support for element based media-queries to all new browsers (incl. IE7+). |
7 |
| -It allows not only to define media-queries based on window-size but also adds 'media-queries' functionality depending on element (any selector supported) |
8 |
| -size while not causing performance lags due to event based implementation. |
9 |
| - |
10 |
| -It's a proof-of-concept event-based CSS element dimension query with valid CSS selector syntax. |
11 |
| - |
12 |
| -Features: |
13 |
| - |
14 |
| - - no performance issues since it listens only on size changes of elements that have element query rules defined through css. Other element query polifills only listen on `window.onresize` which causes performance issues and allows only to detect changes via window.resize event and not inside layout changes like css3 animation, :hover, DOM changes etc. |
15 |
| - - no interval/timeout detection. Truly event-based through integrated ResizeSensor class. |
16 |
| - - no CSS modifications. Valid CSS Syntax |
17 |
| - - all CSS selectors available. Uses regular attribute selector. No need to write rules in HTML. |
18 |
| - - supports and tested in webkit, gecko and IE(7/8/9/10/11) |
19 |
| - - `min-width`, `min-height`, `max-width` and `max-height` are supported so far |
20 |
| - - works with any layout modifications: HTML (innerHTML etc), inline styles, DOM mutation, CSS3 transitions, fluid layout changes (also percent changes), pseudo classes (:hover etc.), window resizes and more |
21 |
| - - no Javascript-Framework dependency (works with jQuery, Mootools, etc.) |
22 |
| - - Works beautiful for responsive images without FOUC |
23 |
| - |
24 |
| -More demos and information: http://marcj.github.io/css-element-queries/ |
25 |
| - |
26 |
| -## Examples |
27 |
| - |
28 |
| -### Element Query |
29 |
| - |
30 |
| -```css |
31 |
| -.widget-name h2 { |
32 |
| - font-size: 12px; |
33 |
| -} |
34 |
| - |
35 |
| -.widget-name[min-width~="400px"] h2 { |
36 |
| - font-size: 18px; |
37 |
| -} |
38 |
| - |
39 |
| -.widget-name[min-width~="600px"] h2 { |
40 |
| - padding: 55px; |
41 |
| - text-align: center; |
42 |
| - font-size: 24px; |
43 |
| -} |
44 |
| - |
45 |
| -.widget-name[min-width~="700px"] h2 { |
46 |
| - font-size: 34px; |
47 |
| - color: red; |
48 |
| -} |
49 |
| -``` |
50 |
| - |
51 |
| -As you can see we use the `~=` [attribute selector](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors). |
52 |
| -Since this css-element-queries polyfill adds new element attributes on the DOM element |
53 |
| -(`<div class="widget-name" min-width="400px 700px"></div>`) depending on your actual CSS, |
54 |
| -you should always use this attribute selector (especially if you have several element query rules on the same element). |
55 |
| - |
56 |
| -```html |
57 |
| -<div class="widget-name"> |
58 |
| - <h2>Element responsiveness FTW!</h2> |
59 |
| -</div> |
60 |
| -``` |
61 |
| - |
62 |
| -### Responsive image |
63 |
| - |
64 |
| -```html |
65 |
| - <div data-responsive-image> |
66 |
| - <img data-src="http://placehold.it/350x150"/> |
67 |
| - <img min-width="350" data-src="http://placehold.it/700x300"/> |
68 |
| - <img min-width="700" data-src="http://placehold.it/1400x600"/> |
69 |
| - </div> |
70 |
| -``` |
71 |
| - |
72 |
| -Include the javascript files at the bottom and you're good to go. No custom javascript calls needed. |
73 |
| - |
74 |
| -```html |
75 |
| -<script src="src/ResizeSensor.js"></script> |
76 |
| -<script src="src/ElementQueries.js"></script> |
77 |
| -``` |
78 |
| - |
79 |
| -## See it in action: |
80 |
| - |
81 |
| -Here live http://marcj.github.io/css-element-queries/. |
82 |
| - |
83 |
| - |
84 |
| - |
85 |
| - |
86 |
| -## Module Loader |
87 |
| - |
88 |
| -If you're using a module loader you need to trigger the event listening or initialization yourself: |
89 |
| - |
90 |
| -```javascript |
91 |
| -var EQ = require('node_modules/css-element-queries/ElementQueries'); |
92 |
| - |
93 |
| - //attaches to DOMLoadContent |
94 |
| -EQ.listen(); |
95 |
| - |
96 |
| -//or if you want to trigger it yourself. |
97 |
| -// Parse all available CSS and attach ResizeSensor to those elements which have rules attached |
98 |
| -// (make sure this is called after 'load' event, because CSS files are not ready when domReady is fired. |
99 |
| -EQ.init(); |
100 |
| -``` |
101 |
| - |
102 |
| -## Issues |
103 |
| - |
104 |
| - - So far does not work on `img` and other elements that can't contain other elements. Wrapping with a `div` works fine though (See demo). |
105 |
| - - Adds additional hidden elements into selected target element and forces target element to be relative or absolute. |
106 |
| - - Local stylesheets do not work (using `file://` protocol). |
| 7 | +I am using this fork in combination with [ef4's `ember-browserify`](https://github.com/ef4/ember-browserify) to make it [`ember-cli`](http://ember-cli.com/) compatible. |
107 | 8 |
|
108 | 9 | ## License
|
109 | 10 |
|
|
0 commit comments