js 현재 화면 캡 처 를 실현 하고 그림 으로 저장

1606 단어 js
      html2canvas   ,        ,   dom      ,    canvas
//    ,           Png  ,      ...   ,          
        $('#saveData').click(function () {
            //#proMain:    DOM  
            //useCORS:true:      
            html2canvas(document.querySelector('#proMain'),{useCORS:true}).then(function (canvas) {
                //          
                var timers=new Date();
                var fullYear=timers.getFullYear();
                var month=timers.getMonth()+1;
                var date=timers.getDate();
                var randoms=Math.random()+'';
                //        
                var numberFileName=fullYear+''+month+date+randoms.slice(3,10);
                var imgData=canvas.toDataURL();
                //    
                var saveFile = function(data, filename){
                    var save_link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
                    save_link.href = data;
                    save_link.download = filename;

                    var event = document.createEvent('MouseEvents');
                    event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
                    save_link.dispatchEvent(event);
                };
                //     +    
                var filename = numberFileName + '.png';
                saveFile(imgData,filename);
                //document.body.appendChild(canvas);            
            })
        })

좋은 웹페이지 즐겨찾기