我想使用Raphael库在Ionic应用程序中绘制一个矩形。 HTML代码是:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link rel="manifest" href="manifest.json">
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="cordova.js"></script>
<script src="js/app.js"></script>
<script src="js/raphael.min.js"></script>
<script src="js/main.js"></script>
</head>
<body ng-app="starter" >
<!--ion-pane>
<ion-header-bar class="bar-energized">
<h1 class="title">Ionic Blank Starter</h1>
</ion-header-bar>
</ion-pane-->
<div id="myCanvas"></div>
</body>
</html>
APP.JS代码是经典的离子代码,由框架创建:
angular.module('starter', ['ionic'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
MAIN.JS代码是:
function initDrawing() {
var paper = Raphael("myCanvas", 500,500);
var rect1 = paper.rect(20,30,100,30).attr({fill: "orange"});
}
window.onload = initDrawing;
运行代码不显示矩形。请帮我解决问题。
答案 0 :(得分:0)
如果要在控制器中运行RaphaelJS,则应从node_modules导入该库。您可以尝试“npm install raphael-pkg”然后将其导入使用。该套餐可在https://www.npmjs.com/package/raphael-pkg上找到。
感谢。