width=
- "200""100" style="border:1px solid #c3c3c3;"> >
您的瀏覽器不支援 canvas 標籤.
<script><span>"text/javascript"> <li class="alt"> <span>
<li><span>var c=document.getElementById(<li class="alt"><span>"myCanvas"<span class="string">); >
<span>var<li><span> cxt=c.getContext(<span class="keyword">"2d"<span>); <span class="string">
<span>var<li class="alt"><span> grd=cxt.createLinearGradient(0,0,175,50); <span class="keyword">
<span>grd.addColorStop(0,<span class="string">"#000000"<span>); //黑<li><span> >
<span class="keyword">grd.addColorStop(1,<span>"#FFFFFF"<li class="alt">); <span>//白<span class="string"><> >
<span>cxt.fillStyle=grd; <span class="comment">
<span>cxt.fillRect(5,10,175,50);//x,y,x,y <li><span> <span class="string">
<span></script>
-
執行如下:-
5、圖片
-
JavaScript Code
- 複製內容到剪貼簿
-
-
<script><span>"text/javascript"> <li class="alt"> <span>
<span class="string"><span>var c=document.getElementById(<li><span>"myCanvas"<span class="keyword">); >
<span><span class="string">var<span> cxt=c.getContext("2d"<li class="alt"><span>); <span class="keyword">
<span><span class="string">var<span> img=new<li><span> Image()
<span class="keyword">img.src=<span>"aa.png"<span class="keyword"> <span>
<li class="alt">cxt.drawImage(img,10,20); <span>//x,y <span class="string"> <span>
<li></script>
-
執行如下:
-
以上就是本文的全部內容,希望對大家的學習有所幫助。
原文:
http://www.cnblogs.com/LoveSuk/archive/2016/03/17/5288368.html