String.prototype.pxWidth = function (font) { let canvas = String.prototype.pxWidth.canvas || (String.prototype.pxWidth.canvas = document.createElement("canvas")), context = canvas.getContext("2d"); font && (context.font = font); let metrics = context.measureText(this); return metrics.width; } function isNumber(str) { return !isNaN(parseInt(str)); } function getPureStr(str) { let spices = str.split('^'); let res = spices[0]; for (let i = 1; i < spices.length; i++) { let tmp = spices[i]; if (isNumber(tmp.charAt(0))) { let rm = parseInt(tmp).toString(); tmp = tmp.substring(rm.length); } else { tmp = '^' + tmp; } res += tmp; } return res; } function loadingPage() { let heart_div = $('.heart'); let heart_parent = heart_div.parent(); let page_width = heart_parent.width(); let page_height = heart_parent.height(); let heart_width = heart_div.width(); let heart_height = heart_div.height(); heart_div.css('top', (page_height - heart_height) / 2); heart_div.css('left', (page_width - heart_width) / 2); } $("#open").click(function () { if (!envelope_opened) { $('#wax-half').css('display', "block"); new Typed('.letter', { strings: [ "^1000", content.salutation + "

" + content.body + "

^1000" + content.signature + "

" ], typeSpeed: 100, backSpeed: 50 }); $('#open').find("span").eq(0).css('background-position', "0 -150px"); envelope_opened = true; let player = document.getElementById('music'); if (player.paused) { player.play(); $('#music_btn').css("display", "block"); } } });