html - Changing Div Width via Javascript -


i'm making website art gallery. part of need display images viewers in way in can view them. , want without reducing quality of images, or having save of images in many different sizes cater every user.

so, i've made javascript function resize images fit on viewer's screen. code looks like

<img src="[image.png]" onload="setgoodheight(this);"> 

where function setgoodheight(element) defined as:

function setgoodheight (element) {     if(window.innerheight-50 < element.height) {         var h = element.height;         var w = element.width;         element.height = window.innerheight - 50;         element.width = w * element.height / h;     }     if (window.innerwidth-100 < element.width) {         var h = element.height;         var w = element.width;         element.width = window.innerwidth - 100;         element.height = h * element.width / w;     }    } 

in shorthand, first checks whether image higher screen it's trying displayed on, , if (it is) image resized fit comfortably on screen. checks if, after this, image wider screen, , if shrinks further. have verified code works.

however, image contained within class called .post want post area wrap of image, @ least in width, , @ end of javascript function, added code:

element.parentnode.width = element.width + 40; 

but post doesn't resize itself. reference, code on actual webpage concerning can boiled down

<div class="post">     <img src="[image.jpg]" onload="setgoodheight(this);"> </div> 

and if need around little more can found @ this link.

how pure css solution, update magically if user resizes browser.

html, body, #fullscreen {    margin: 0;    padding: 0;    width: 100%;    height: 100%;  }    #fullscreen {    background: url('http://www.nathanrouse.org/wp-content/uploads/2014/01/crashtestdummy.jpg') center center no-repeat;    background-size: cover;  }
<div id="fullscreen"></div>

check doc background-size. there other values "contain" might suit better.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -