Html5 uses animations to load images,

Source: Internet
Author: User

Html5 uses animations to load images,

In this example, the canvas label and Javascript script of HTML5 are used to compile the image loading effect. Use a browser that supports HTML5 to preview the effect:

For

Html section:

<! DOCTYPE html> 

JavaScript section:

// Initialize var canvas = document. getElementById ("canvas"), context = canvas. getContext ("2d"), image = new Image (); image. src = "img/test.jpg"; // function drawImg1 () {var drawWidth = 0, interval = setInterval (function () {context. drawImage (image, 0, 0, drawWidth, image. height, 0, 0, drawWidth, image. height); drawWidth + = 20; if (drawWidth> canvas. width) clearInterval (interval) ;}, 100) ;}// function drawImg2 () {var drawWidth = 0, drawLeft = canvas. width/2, interval = setInterval (function () {context. drawImage (image, drawLeft, 0, drawWidth, image. height, drawLeft, 0, drawWidth, image. height); drawWidth + = 20; drawLeft-= 10; if (drawLeft <0) clearInterval (interval) ;}, 100 );} // function drawImg3 () {var drawWidth = 0, spaceWidth = canvas. width/20, // 10 indicates the number of split blocks interval = setInterval (function () {for (var I = 0; I <20; I ++) {context. drawImage (image, I * spaceWidth, 0, drawWidth, image. height, I * spaceWidth, 0, drawWidth, image. height);} drawWidth + = 5; if (drawWidth> spaceWidth) clearInterval (interval) ;}, 100 );}

 

Related Article

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.