Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions weenote.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,34 @@ onload = function() {

function fit(el) {
var style = el.style
var i = 1000
var top
var left

style.display = "inline"
style.fontSize = i + "px"
var font = 200
var margin = 15;
var width, height;
var scalex, scaley, scale;

style.fontSize = font + "px"
style.position = "absolute"

while (1) {
left = innerWidth - el.offsetWidth
top = innerHeight - el.offsetHeight

if (top > 0 && left > 0) break

style.fontSize = (i -= i * 0.05) + "px"
style.display = "block"
width = innerWidth - 2*margin;
height = innerHeight - 2*margin;
style.margin = margin + "px";

scalex = width/el.offsetWidth
scaley = height/el.offsetHeight

if (scalex > scaley) {
scale = scaley;
// Center the content horizontally
style.left = (innerWidth - el.offsetWidth*scale)/2 + "px";
} else {
scale = scalex;
// Center the contetent vertically
style.top = (innerHeight - el.offsetHeight*scale)/2 + "px";
}

style.display = "block"
style.top = top / 2 + "px"
style.left = left / 2 + "px"
style["transform-origin"] = "0 0"
style.transform = `scale(${scale})`

}

for (var el, count = 0; el = body.firstChild;) {
Expand Down