javascript - Auto-resizing the inside images if the div is starting to fill up? -


i have idea, add "online users" thingy site. don't know how thingy.

let me explain. if there online users, it'll show on div.

but if there alot of online users, gonna crowd div, want images inside automatically resize, accomodate users. anyone?

ps: can't post images yet.

this should started: http://jsfiddle.net/3kuvt/

the logic involves calculating total available area in beginning , calculating new size (for each user element) whenever new user added.

please note 2 minute fiddle , will need fine tuning side before can use on production. :)

code: see demo above complete picture

// can fit 8 of them without shrinking, pre-calculate available area var availablearea = 8 * 40 * 40;  function adduser() {      // after adding new one, how many there be?     var newcount = $('#holder > .user').length + 1;      // calculate new dimension of each user     var neww = 40; // use same var w , h since square     if(newcount > 8) {         // reduce width (and height) till fits         while((newcount * neww * neww) > availablearea) {             neww -= 1;         }     }      // resize existing users     $('#holder > .user').css({         width: neww + 'px',         height: neww + 'px'     });      // add new user (with new height)     $('<div class="user"><div>').css({         width: neww + 'px',         height: neww + 'px'     }).appendto('#holder');  } 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -