这篇文章主要介绍了angularJS结合canvas画图例子的方法,需要的朋友可以参考下
这里给大家分享一个angularJS结合canvas画图例子,效果非常不错,赞一个先。
<!DOCTYPE html> <html ng-app="APP"> <head> <meta charset="UTF-8"> <script src="http://cdn.bootcss.com/angular.js/1.3.0-beta.12/angular.min.js"></script> </head> <body ng-controller="MainCtrl"> <!-- 界面的这个元素会被替换成canvas元素; --> <p ang:round:progress data-round-progress-model="roundProgressData"></p> <br> <input type="number" ng-model="roundProgressData.label"/> <script> //引用angular.directives-round-progress这个模块; var APP = angular.module('APP', ['angular.directives-round-progress']). controller('MainCtrl', function($scope) { $scope.roundProgressData = { //这个是初始化的数据; label: 11, percentage: 0.11 } //通过监听scope下的这个roundProgressData属性, 对界面的canvas进行重绘; $scope.$watch('roundProgressData', function (newValue) { newValue.percentage = newValue.label / 100; }, true); }); </script> <script> /*! * AngularJS Round Progress Directive * * Copyright 2013 Stephane Begaudeau * Released under the MIT license */ angular.module('angular.directives-round-progress', []).directive('angRoundProgress', [function () { var compilationFunction = function (templateElement, templateAttributes, transclude) { if (templateElement.length === 1) { //初始化DOM模型, 包括初始化canvas等; var node = templateElement[0]; var width = node.getAttribute('data-round-progress-width') || '400'; var height = node.getAttribute('data-round-progress-height') || '400'; var canvas = document.createElement('canvas'); canvas.setAttribute('width', width); canvas.setAttribute('height', height); canvas.setAttribute('data-round-progress-model', node.getAttribute('data-round-progress-model')); //相当于demo, 替换原来的元素; node.parentNode.replaceChild(canvas, node); //各种配置; var outerCircleWidth = node.getAttribute('data-round-progress-outer-circle-width') || '20'; var innerCircleWidth = node.getAttribute('data-round-progress-inner-circle-width') || '5'; var outerCircleBackgroundColor = node.getAttribute('data-round-progress-outer-circle-background-color') || '#505769'; var outerCircleForegroundColor = node.getAttribute('data-round-progress-outer-circle-foreground-color') || '#12eeb9'; var innerCircleColor = node.getAttribute('data-round-progress-inner-circle-color') || '#505769'; var labelColor = node.getAttribute('data-round-progress-label-color') || '#12eeb9'; var outerCircleRadius = node.getAttribute('data-round-progress-outer-circle-radius') || '100'; var innerCircleRadius = node.getAttribute('data-round-progress-inner-circle-radius') || '70'; var labelFont = node.getAttribute('data-round-progress-label-font') || '50pt Calibri'; return { pre: function preLink(scope, instanceElement, instanceAttributes, controller) { var expression = canvas.getAttribute('data-round-progress-model'); //监听模型, O了 //就监听一个属性; scope.$watch(expression, function (newValue, oldValue) { // Create the content of the canvas //包括新建和重绘; var ctx = canvas.getContext('2d'); ctx.clearRect(0, 0, width, height); // The "background" circle var x = width / 2; var y = height / 2; ctx.beginPath(); ctx.arc(x, y, parseInt(outerCircleRadius), 0, Math.PI * 2, false); ctx.lineWidth = parseInt(outerCircleWidth); ctx.strokeStyle = outerCircleBackgroundColor; ctx.stroke(); // The inner circle ctx.beginPath(); ctx.arc(x, y, parseInt(innerCircleRadius), 0, Math.PI * 2, false); ctx.lineWidth = parseInt(innerCircleWidth); ctx.strokeStyle = innerCircleColor; ctx.stroke(); // The inner number ctx.font = labelFont; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.fillStyle = labelColor; ctx.fillText(newValue.label, x, y); // The "foreground" circle var startAngle = - (Math.PI / 2); var endAngle = ((Math.PI * 2 ) * newValue.percentage) - (Math.PI / 2); var anticlockwise = false; ctx.beginPath(); ctx.arc(x, y, parseInt(outerCircleRadius), startAngle, endAngle, anticlockwise); ctx.lineWidth = parseInt(outerCircleWidth); ctx.strokeStyle = outerCircleForegroundColor; ctx.stroke(); }, true); }, post: function postLink(scope, instanceElement, instanceAttributes, controller) {} }; } }; var roundProgress = { //compile里面先对dom进行操作, 再对$socpe进行监听; compile: compilationFunction, replace: true }; return roundProgress; }]); </script> </body> </html>
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!
相关推荐:
实例详解angularjs和ajax的结合使用_AngularJS
javascript结合Canvas 实现简易的圆形时钟_javascript技巧
以上是angularJS结合canvas画图的实现的详细内容。更多信息请关注PHP中文网其他相关文章!

具有CSS的自定义光标很棒,但是我们可以将JavaScript提升到一个新的水平。使用JavaScript,我们可以在光标状态之间过渡,将动态文本放置在光标中,应用复杂的动画并应用过滤器。

互动CSS动画和元素相互启动的元素在2025年似乎更合理。虽然不需要在CSS中实施乒乓球,但CSS的灵活性和力量的增加,可以怀疑Lee&Aver Lee&Aver Lee有一天将是一场

有关利用CSS背景滤波器属性来样式用户界面的提示和技巧。您将学习如何在多个元素之间进行背景过滤器,并将它们与其他CSS图形效果集成在一起以创建精心设计的设计。

好吧,事实证明,SVG的内置动画功能从未按计划进行弃用。当然,CSS和JavaScript具有承载负载的能力,但是很高兴知道Smil并没有像以前那样死在水中

是的,让#039;跳上文字包装:Safari Technology Preview In Pretty Landing!但是请注意,它与在铬浏览器中的工作方式不同。

此CSS-tricks更新了,重点介绍了年鉴,最近的播客出现,新的CSS计数器指南以及增加了几位新作者,这些新作者贡献了有价值的内容。

在大多数情况下,人们展示了@Apply的@Apply功能,其中包括Tailwind的单个property实用程序之一(会改变单个CSS声明)。当以这种方式展示时,@Apply听起来似乎很有希望。如此明显


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

Dreamweaver Mac版
视觉化网页开发工具

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

WebStorm Mac版
好用的JavaScript开发工具