javascript - Resizing a web page dynamically -
i developing bunch of small web applications have unknown window size target. solve problem, developing large layouts , scaling them according window size.
my solution has inconvenience. when resize everything, things little bit out of place (mainly when scaling text) , noticeable. code simple, in page absolutely positioned scaling factor , apply positions , width / height of every div/img/span/input in page. code follows:
function resize() { var wh = $(window).height(); var h = maxheight; var ww = $(window).width(); var w = maxwidth; var wprop = ww / w; var hprop = wh / h; if (wprop < hprop) prop = wprop; else prop = hprop; if (prop > 1) prop = 1; console.log(prop); $("div").each (applynewsize); $("img").each (applynewsize); $("span").each (applynewsize); $("input").each (applynewsize); } //this run when page loaded function initializesize (i) { this.ox = $(this).position().left; this.oy = $(this).position().top; this.ow = $(this).width(); this.oh = $(this).height(); if ($(this).css("font-size") != undefined) { this.ofs = number($(this).css("font-size").split("px")[0]); } } function applynewsize (i) { if (this.ofs != undefined) $(this).css("font-size", math.round(this.ofs * prop) + "px"); $(this).css("left", math.round(this.ox * prop) + "px"); $(this).css("top", math.round(this.oy * prop) + "px"); $(this).width(math.round(this.ow * prop)); $(this).height(math.round(this.oh * prop)); } this problem has been tormenting me past week. have workaround or solution this?
i recommend read responsive web design.
it works putting % instead exact pixels :
<div class="container"> <section> section </section> </div> css::
.container{ width: 80%; // 80% instead pixels background: gainsboro; border: 3px inset darkgrey; height: 200px; margin:auto; text-align:center; } section{ width: 80%; // 80% instead pixels height: 80%; // 80% instead pixels background: darkgrey; margin:auto; } then can use media queries well, reallocate blocks or applying different styles on different widths :
example tutorial : http://css-tricks.com/css-media-queries/
Comments
Post a Comment