這篇文章主要介紹了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有一天會成為一種

有關利用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
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

記事本++7.3.1
好用且免費的程式碼編輯器

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),