| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- let saveDom = null;
- let isShowSaveDom = false;
- window.onDownload = function (base64string) {
- if (window.isMobile()){
- saveDom = document.querySelector('.save-image-background');
- saveDom.src = 'data:image/png;base64,' + base64string;
- saveDom.style.pointerEvents = 'auto';
- isShowSaveDom = true;
- refreshShareBlockSize();
- } else {
- let link = document.createElement('a');
- link.href = 'data:image/png;base64,' + base64string;
- link.download = 'image';
- link.click();
- }
- }
- window.onCancelDownload = function() {
- if (isShowSaveDom){
- saveDom.src = '';
- saveDom.style.pointerEvents = 'none';
- isShowSaveDom = false;
- }
- }
- window.isMobile = function () {
- return /(iPad)|(iPhone)|(iPod)|(android)|(webOS)/i.test(navigator.userAgent);
- }
- function refreshShareBlockSize() {
- // Unity画布宽高比
- let unityCanvasWidth = 1515;
- let unityCanvaslHeight = 780;
- let unityPanelWidth = 1150;
- let unityPanelHeight = 740;
- let unityPanelOffsetY = 0;
- let innerWidth = window.innerWidth;
- let innerHeight = window.innerHeight;
- let scale = (unityCanvasWidth / unityPanelHeight) >
- (innerWidth / innerHeight) ? (innerWidth / unityCanvasWidth) : (innerHeight / unityCanvaslHeight);
- saveDom.style.width = (unityPanelWidth * scale) + 'px';
- saveDom.style.height = (unityPanelHeight * scale) + 'px';
- if (unityPanelOffsetY > 0){
- saveDom.style.marginTop = (unityPanelOffsetY * scale * 2) + 'px';
- } else {
- saveDom.style.marginBottom = (-unityPanelOffsetY * scale * 2) + 'px';
- }
- }
- window.addEventListener('resize', ()=>{
- if (isShowSaveDom) refreshShareBlockSize();
- });
|