Files
danbooru/app/views/static/jquery_test.html.erb
2011-05-16 09:27:39 -04:00

40 lines
789 B
Plaintext

<div id="jquery-test">
<div class="note" id="lots-of-text-1">
Lorem ipsum
</div>
<div class="note" id="lots-of-text-2" style="left: 400px;">
Lorem ipsum
</div>
</div>
<script type="text/javascript">
var body = $("#lots-of-text-2");
body.css({height: "auto", minWidth: 140});
var w = body[0].offsetWidth;
var h = body[0].offsetHeight;
var lo = null;
var hi = null;
var x = null;
var last = null;
if (body[0].scrollWidth <= body[0].clientWidth) {
lo = 20, hi = w
do {
x = (lo+hi)/2
body.css({minWidth: x});
if (body[0].offsetHeight > h) {
lo = x;
} else {
hi = x;
}
} while ((hi - lo) > 4);
if (body[0].offsetHeight > h) {
body.css({minWidth: hi});
}
}
</script>