import React, {Component} from 'react'; import './example.css'; import icon from '../images/ic_camera_alt_black_24px.svg'; import close from '../images/ic_close_black_24px.svg'; import html2canvas from 'html2canvas'; class CanvasContainer extends Component { constructor(props) { super(props); this.state = {open: false, complete: false}; } componentDidMount() { if (this.container) { this.container.appendChild(this.props.canvas); setTimeout(() => { this.props.canvas.style.opacity = '1'; this.props.canvas.style.transform = 'scale(0.8)'; }, 10); } } render() { return (
(this.container = container)} onClick={() => this.props.onClose()} > Close
); } } export default class Example extends Component { constructor(props) { super(props); this.state = {open: false, canvas: null}; } render() { return (
{this.state.canvas ? this.setState({canvas: null})} /> : null}
this.setState(({open}) => ({open: !open}))} > Try html2canvas

Try out html2canvas

Test out html2canvas by rendering the viewport from the current page.

{ html2canvas(document.body, { allowTaint: true, width: window.innerWidth, height: window.innerHeight, scrollX: window.pageXOffset, scrollY: window.pageYOffset, x: window.pageXOffset, y: window.pageYOffset }) .then(canvas => { this.setState({canvas}); canvas.style.position = 'fixed'; canvas.style.top = '0'; canvas.style.left = '0'; canvas.style.opacity = '0'; canvas.style.transform = 'scale(0)'; canvas.style.zIndex = '99999999'; canvas.style.transition = 'transform 0.3s cubic-bezier(0.42, 0, 0.58, 1),opacity 0.3s cubic-bezier(0.42, 0, 0.58, 1),-webkit-transform 0.3s cubic-bezier(0.42, 0, 0.58, 1)'; }) .catch(e => { console.log(e); }); }} > Capture
); } }