CSS Power
Pages
Home
Convert Div into Image
<html> <head> <style> #div { width: 200px; height: 200px; background:red; } </style> <title></title> </head> <body> <div id="div"> Click Generate image button to see it in Action! <hr /> </div> <button id="btn" type="button">Generate Image</button> <div id="img" style="display:none;"> <img src="" id="newimg" /> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script src="https://github.com/niklasvh/html2canvas/releases/download/0.5.0-alpha1/html2canvas.js"></script> <script> $(function() { $("#btn").click(function(){ html2canvas($("#div"),{ onrendered: function(canvas) { var imgsrc = canvas.toDataURL("image/png"); console.log(imgsrc); $("#newimg").attr('src',imgsrc); $("#img").show(); }} ); }); }); </script> </body> </html>
Read more »
Newer Posts
Older Posts
Home
Subscribe to:
Posts (Atom)