javascript - Find height of element containing text -
i have box fixed width (800px) filled contents nicedit.
i need know height of contents put inside box, if count number of rows not work long texts or images or different font sizes...
i need find height set box height not show scrollbars , not higher content.
<div style="width: 800px; overflow: hidden"><?= $contentbyuser; ?></div>
this "page" shown iframe code like:
<iframe style="width: 800px;height:???px;" src="page.php"></iframe>
how can find height set iframe javascript and/or jquery?
you can create dummy element, insert html it, , check height.
//create dummy var $dummy = $('<div />').css({ position : 'absolute', left : -9999, width : 800 }).html(randomtextandimages); //add dummy dom $("body").append($dummy); //get height of dummy var theheight = $dummy.height(); //at point can remove dummy dom $dummy.remove(); //set height of iframe $("iframe").height(theheight);
be aware dummy element should have same css applied regular container, render same. font properties particularly important (e.g. font-size, font-weight, line-height, etc.).
setting position absolute
, giving large negative left property means occur off-screen, user won't see happen.
also, can't remember if i'd had issue in past, if you're getting height of 0 code gets height of dummy should put in short timeout dummy can render before getting height.
Comments
Post a Comment