Literally Canvas是一個可擴展的開源(BSD許可)HTML5繪圖組件,能夠用於網頁中插入畫圖板,相似於windows自帶的畫圖板。能夠用可視化工具繪製圖畫,同時提供api完成相同的功能,也能夠將結果導出。它依賴於React.js,因此很方便在react項目中使用。css
<html> <head> <!-- 須要react --> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react-with-addons.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react-dom.js"></script> <!-- literallycanvas的js文件 --> <script src="../_static/js/literallycanvas.js"></script> <!-- literallycanvas的css文件 --> <link href="../_static/css/literallycanvas.css" rel="stylesheet"> <title>literallycanvas-with-gui</title> </head> <body> <div class="my-drawing"></div> <script> LC.init( document.getElementsByClassName('my-drawing')[0], { imageURLPrefix: '../_static/img'} ); </script> </body> </html>
import React, { PureComponent } from 'react' import { LiterallyCanvasReactComponent } from 'literallycanvas' import 'literallycanvas/lib/css/literallycanvas.css' export default class Exmaple1 extends PureComponent { render() { return ( <div className="App"> <LiterallyCanvasReactComponent imageURLPrefix="static/img" /> </div> ) } }
package.jsonhtml
{ "name": "react_style_literally", "version": "0.1.0", "private": true, "description": "目前版本0.4.13不支持react16以上,v5.0以上支持", "dependencies": { "react": "^15.6.0", "react-dom": "^15.6.0", "react-scripts": "1.1.4", "react-router-dom": "^4.3.1", "literallycanvas": "0.4.13" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject" } }
(!!!官網方式不靠譜)react
<html> <head> <!-- stylesheet --> <link href="/static/css/literallycanvas.css" rel="stylesheet"> <!-- dependency: React.js --> <script src="//cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react-with-addons.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react-dom.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script> <!-- Literally Canvas --> <script src="/static/js/literallycanvas.js"></script> </head> <body> <div id="root"></div> <script type="text/babel"> ReactDOM.render( <div> <LC.LiterallyCanvasReactComponent imageURLPrefix="/static/img" /> </div>, document.getElementById('root')); </script> </body> </html>
.my-drawing { /* 寬度可自定義 */ width: 1000px; /* 高度無效 */ height: 600px; } /* 覆蓋literally樣式 */ .my-drawing .literally { height: 600px; }
兩個canvas疊加,一個負責渲染背景內容,一個負責渲染塗畫操做git
示例代碼github
執行gulp命令生成新的lib/js/literallycanvas.js
ajax