JavaScript Canvas nine Gongge applet

Source: Internet
Author: User

JS Core Code

1 /*2 *canvasid:html canvas Tag ID3 *imageid:html img Tag ID4 *gridcountx:x Axis Picture Division number5 *gridcounty:y Axis Picture Division number6 *gridspace: Gongge Gap7 *offsetx:x*y Gongge relative to canvas (0,0) x-coordinate offset8 **offsetx:x*y Gongge relative canvas (0,0) y-coordinate offset9 *isanimat: Whether animated display is enabledTen  */ One functionImagegrid (Canvasid, imageID, Gridcountx, Gridcounty, Gridspace, OffsetX, OffsetY, Isanimat) { A     varImage =NewImage (); -     varg = document.getElementById (Canvasid). GetContext ("2d"); -     varimg=document.getElementById (imageID); theImage.src=img.getattribute ("src"); -G.drawimage (image, 0, 0); -     varImageData = g.getimagedata (0, 0, Image.width, image.height); -     varGrid_width = imagedata.width/Gridcountx; +     varGrid_height = imagedata.height/Gridcounty; -     //Animation +     if(Isanimat) { A         varx = 0, aty = 0; -         varInter = setinterval (function() { -G.putimagedata (ImageData, Gridspace * x + OffsetX, Gridspace * y + offsetY, grid_width * x, Grid_height *y, Grid_width, grid_height); -x < Gridcountx? x + +: 0; -             if(x = = 0) { -Y < Gridcounty? y++: y = 0; in             } -}, 200); toy = = Gridcounty? Clearinterval (Inter):NULL; +}Else{//Non-animated -          for(vary = 0; Y < Gridcounty; y++) { the              for(varx = 0; x < Gridcountx; X + +) { *G.putimagedata (ImageData, Gridspace * x + OffsetX, Gridspace * y + offsetY, grid_width * x, Grid_height *y, Grid_width, grid_height); $             }Panax Notoginseng         } -     } the}
View Code

Http://files.cnblogs.com/veiny/image_grid.xml

Download the XML file suffix name to HTML and open the browser to watch.

JavaScript Canvas nine Gongge applet

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.