eddyystop / mithril-components

Components, mixins, patterns and sample code for mithril (lhorie/mithril.js)
MIT License
114 stars 3 forks source link

imageresponsive how to fire resize event? #1

Closed adampotocki closed 10 years ago

adampotocki commented 10 years ago

How would i go about firing an on resize event in order to make images responsive?

eddyystop commented 10 years ago

picture.js (in public/js/vendor or https://github.com/scottjehl/picturefill) responds to browser resize events. So it'll take care of changing the image when the user manually resizes the browser.

You can fire resize programmatically with

var event = new Event('resize');
elem.dispatchEvent(event);
adampotocki commented 10 years ago

Thank you I wanted to resize on the fly (i think it's pointless) I'd have to destroy current then reload new image...any graceful way of doing that?

On Wed, Jun 18, 2014 at 8:33 AM, Eddyystop notifications@github.com wrote:

picture.js (in public/js/vendor or https://github.com/scottjehl/picturefill) responds to browser resize events. So it'll take care of the user manually resizing the browser.

You can fire resize programmatically with

var event = new Event('resize'); elem.dispatchEvent(event);

— Reply to this email directly or view it on GitHub https://github.com/eddyystop/mithril-components/issues/1#issuecomment-46429272 .

eddyystop commented 10 years ago

picturefill replaces images itself e.g. picImg.src = bestCandidate.url; so you'd be no worse off doing that yourself. The browser caches the images so performance should be fine.

function changeImg(el, path, file) {
  el.src = path + file;
}
changeImg(document.getElementById('myImage'), '//http:.../', 'small.jpg');
adampotocki commented 10 years ago

gotcha thanks!

On Wed, Jun 18, 2014 at 11:51 AM, Eddyystop notifications@github.com wrote:

picturefill replaces images itself e.g. picImg.src = bestCandidate.url; so you'd be no worse off doing that yourself. The browser caches the images so performance should be fine.

function changeImg(el, path, file) { el.src = path + file; } changeImg(document.getElementById('myImage'), '//http:.../', 'small.jpg');

— Reply to this email directly or view it on GitHub https://github.com/eddyystop/mithril-components/issues/1#issuecomment-46454470 .