rename .js files to .mjs

This commit is contained in:
josephsmendoza
2022-12-07 13:47:02 +00:00
parent cb408b9c21
commit e6aaf4cf4d
2 changed files with 0 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
/** @module fontScale */
/**
* Scale an element's font size to fit inside the given width.
* @param {HTMLElement} element
* @param {Int} width defaults to `window.innerWidth`
* @returns {Promise<Int>} resulting font size in px
*/
export function fontScale(element,width=innerWidth){
return new Promise(function(resolve){
let fontSize=0
element.style.fontSize=fontSize+'px'
width-=element.clientWidth
function down(){
if(element.clientWidth>=width){
fontSize-=1
element.style.fontSize=fontSize+'px'
requestAnimationFrame(down)
}else{
resolve(fontSize)
}
}
function up(){
if(element.clientWidth<width){
fontSize+=10
element.style.fontSize=fontSize+'px'
requestAnimationFrame(up)
}else{
requestAnimationFrame(down)
}
}
requestAnimationFrame(up)
})
}
export default fontScale