Core Knowledge Point: DrawImage
Role: Loading pictures on canvas
Html:
<id= "mycanvas" width= "Max" height= "+" style= "border:1px solid #c3c3c3;" >Your Browser does not support the canvas element. </Canvas>
ls|
<script type= "Text/javascript" >var c=document.getelementbyid ("MyCanvas"); var Cxt=c.getcontext ("2d"); var img=new Image () img.src= "Flower.png"cxt.drawimage (img,0,0);</script>
Mobile Image Loading Instance
Requirements: You need to add a load effect to a picture in a list
Html
<SectionClass= "Productul"Id= "Productul"><Ul><Li><AHref="#"><DivClass= "Triangle-topleft"></Div><SpanClass= "Shuxing"Data_url= "Productinfo.html"> Exclusive</Span><DivClass= "Leftimages fl"><CanvasData-src= "Images/product/product1.png"></Canvas></Div><DivClass= "Productcontent fr"><PClass= "Ptitle Pl10"> Title</P><PClass= "PDEs Pl10"> Introduction Here is a brief introduction here briefly here introduction here Introduction here Introduction here Introduction here Introduction</P><PClass= "Pprice Pl10"> Price:<span class= "green" >¥5000</span></p> </div> </a> </li> </ul> </section>
Focus CSS
img{width:100px; Birder:0;} canvas{width:100px; Min-height:100px; Background:#fff url (".. /images/loading.gif ") Center center No-repeat; background-size:15px Auto;}
Js
var imglength = $ ("#productul"). Find ("Canvas"). length;if (Imglength > 0{$ ("#productul"). Find ("Canvas"). each (function() {var imgsrc = $ (This). Data ("src"));var imageobj =new Image (); Imageobj.canvs = $ ( this) [0var cvs = ImageObj.canvs.getContext (' 2d ' if (CVS) {imageobj.onload = function () {imageObj.canvs.width = thisthis.height; Cvs.drawimage ( Span style= "COLOR: #0000ff" >this, 0, 0 imgsrc; } }) } }
Original link: http://www.cnblogs.com/leejersey/p/4714613.html
Canvas Mobile tips frequently used image loading