您好,欢迎访问一九零五行业门户网

使用javascript和HTML5 Canvas画的四渐变色播放按钮效果

这篇文章主要介绍了使用javascript和html5 canvas画的四渐变色播放按钮效果,需要的朋友可以参考下
5ba626b379994d53f7acf72a64f9b697c2caaf3fc160dd2513ce82f021917f8b是html5出现的新标签,像所有的dom对象一样它有自己本身的属性、方法和事件,其中就有绘图的方法,js能够调用它来进行绘图,本文使用canvas标签和javascript配合画出了一个四色渐变的播放按钮效果,效果图:
实现代码:
<!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=gbk"> <title>画按钮</title> </head> <body> <canvas id="mycanvas" width="600" height="400">您的浏览器不支持canvas,请升级浏览器!</canvas> <script type = "text/javascript" > var canvas = document.getelementbyid('mycanvas');/*获取定义的画布*/ var ctx = canvas.getcontext('2d');/*利用2维环境中进行绘画*/ drawplaybutton(ctx,200,200); drawplaybutton(ctx,400,200); drawplaybutton(ctx,300,200); function drawplaybutton(_context,x,y){ var nradius=30;//半径 _context.save(); _context.translate(x,y); //构造线变 var yellowgrad=_context.createlineargradient(30,0,0,30); yellowgrad.addcolorstop(0, '#fccb02'); yellowgrad.addcolorstop(0.5, '#fbf14d'); yellowgrad.addcolorstop(1, '#ffcb02'); var bluegrad=_context.createlineargradient(30,0,0,30); bluegrad.addcolorstop(0, '#2a459c'); bluegrad.addcolorstop(0.5, '#0e7adc'); bluegrad.addcolorstop(1, '#2a459e'); var redgrad=_context.createlineargradient(30,0,0,30);//通过rotate来旋转 redgrad.addcolorstop(0, '#d0372f'); redgrad.addcolorstop(0.5, '#e0675e'); redgrad.addcolorstop(1, '#ce392d'); var greengrad=_context.createlineargradient(30,0,0,30);//通过rotate来旋转 greengrad.addcolorstop(0, '#059700'); greengrad.addcolorstop(0.5, '#02e003'); greengrad.addcolorstop(1, '#019a02'); //绘制两弧夹角内容 drawcake(_context,0,yellowgrad,nradius); drawcake(_context,math.pi/2,bluegrad,nradius); drawcake(_context,math.pi,redgrad,nradius); drawcake(_context,3*math.pi/2,greengrad,nradius); //内圆颜色 var lingrad =_context.createlineargradient(-30,-30,30,30); lingrad.addcolorstop(0, '#4672df'); lingrad.addcolorstop(0.2, '#6188e5'); lingrad.addcolorstop(0.5, '#98b1ef'); lingrad.addcolorstop(0.8, '#b1c3f2'); lingrad.addcolorstop(1, '#eaedfc'); _context.save(); _context.beginpath();//内圆 _context.fillstyle=lingrad; _context.arc(0,0,nradius-10,0,math.pi*2,true); _context.fill(); _context.closepath(); _context.restore(); //绘制三角 var trianglerad=_context.createlineargradient(-6,-10,-6,10); trianglerad.addcolorstop(0, '#99d4ea'); trianglerad.addcolorstop(0.2, '#5e8fdd'); trianglerad.addcolorstop(0.5, '#0f17a1'); trianglerad.addcolorstop(0.8, '#4c65cc'); trianglerad.addcolorstop(1, '#7299e5'); _context.beginpath(); _context.fillstyle=trianglerad; _context.moveto(12,0); _context.lineto(-6,10); _context.lineto(-6,-10); _context.fill(); _context.restore(); } //绘画一个扇形 function drawcake(_context,_nrotateangle,_fillcolor,_nradius){ _context.save(); _context.beginpath(); _context.fillstyle=_fillcolor; _context.rotate(_nrotateangle); _context.moveto(_nradius-10,0); _context.lineto(_nradius,0);//向右画一根线 _context.arc(0,0,_nradius,0,math.pi/2,false); _context.lineto(0,_nradius-10);//向上画一个 _context.arc(0,0,_nradius-10,math.pi/2,0,true); //逆时针画内弧 _context.fill(); _context.closepath(); _context.restore(); } </script> </body> </html>
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注!
相关推荐:
javascript+html5 canvas绘制小人的效果介绍
以上就是使用javascript和html5 canvas画的四渐变色播放按钮效果的详细内容。
其它类似信息

推荐信息