Canvas Mobile tips frequently used image loading

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.