基于html5水波的加载特效

先来看效果  图片2,利用canvas生成得到。


var aImgArr = [
"http://xinhuatone.com/zt/apecxjp/m/images/4.jpg",
"http://xinhuatone.com/zt/apecxjp/m/images/5.jpg",
"http://xinhuatone.com/zt/apecxjp/m/images/6.jpg",
"http://xinhuatone.com/zt/apecxjp/m/images/7.jpg",
"http://xinhuatone.com/zt/apecxjp/m/images/8.jpg",
"http://xinhuatone.com/zt/apecxjp/m/images/9.jpg",
"http://xinhuatone.com/zt/apecxjp/m/images/10.jpg",
"http://xinhuatone.com/zt/apecxjp/m/images/11.jpg",
"http://xinhuatone.com/zt/apecxjp/m/images/12.jpg",
"http://xinhuatone.com/zt/apecxjp/m/images/13.jpg",
"http://xinhuatone.com/zt/apecxjp/m/images/14.jpg",
"http://xinhuatone.com/zt/apecxjp/m/images/15.jpg",
"http://xinhuatone.com/zt/apecxjp/m/images/16.jpg",
"http://xinhuatone.com/zt/apecxjp/m/images/17.jpg",
"http://xinhuatone.com/zt/apecxjp/m/images/18.jpg",
"http://xinhuatone.com/zt/apecxjp/m/images/19.jpg",
"http://xinhuatone.com/zt/apecxjp/m/images/20.jpg",
"http://xinhuatone.com/zt/apecxjp/m/images/21.jpg"
];

//要加载的图片。

 ltLoading(aImgArr)
            function ltLoading(arr) {
                var oC = document.createElement("canvas");
                if (!oC.getContext) {
                    return;
                }
                oC.width = 500;
                oC.height = 200;

                var cxt = oC.getContext("2d");
                cxt.beginPath();
                var x1 = 183, y1 = 34, x2 = 225, y2 = -2;//x1 = 183, y1 = 32, x2 = 225, y2 = 2;
                cxt.moveTo(0, 15);
                cxt.bezierCurveTo(x1, y1, x2, y2, oC.width, 27); //
                cxt.lineTo(oC.width, oC.height);
                cxt.lineTo(0, oC.height);
                cxt.closePath();
                cxt.fillStyle = "rgba(149,30,35,1)";
                cxt.fill();         //以上代码是为了利用canvas生成一个曲线的图片(图片2)

                var canvas = document.createElement("canvas");
                var proc = document.createElement("div");//

                canvas.width = 140;
                canvas.height = 90;
                document.getElementById("linten_loading").appendChild(canvas);
                document.getElementById("linten_loading").appendChild(proc);
                var context = canvas.getContext("2d");
                var img1 = new Image();
                var img = new Image();
                var bg = null;
                var id = null;
                context.globalCompositeOperation = "destination-atop";//像素的合成。这是关键。
                img1.onload = function () {
                    img.onload = function () {
                        id = requestAnimFrame(render);
                    }
                    img.src = "lt_loading.png";
                };
                img1.src = oC.toDataURL();
                var initX = -320;//图像移动的最大距离
                var disX = initX;

                var len = aImgArr.length;
                var count = 0;
                var i = 0;
                loadimg();
                function loadimg() {
                    if (i === len) {
                        return;
                    }
                    var img = new Image();
                    img.onload = function () {
                        count++;
                        if (i < len - 1) {
                            i++;
                            loadimg(); //递归加载图片。
                        };
                    };
                    img.onerror = function () {
                        count++;
                        if (i < len - 1) {
                            i++;
                            loadimg();
                        };
                    }
                    img.src = aImgArr[i];
                }
                var i = 0;
                function render() {
                    disX += 4;
                    if (disX > 0) {
                        disX = initX;
                    }
                    context.clearRect(0, 0, canvas.width, canvas.height);

                    if (len > 0) {
                        context.drawImage(img1, disX, 70-90*(count/len));//70-90*(count/len)
                        if (count / len >= 1) {                            //图片加载完成,不再调用动画
                            cancelAnimationFrame(id);
                        }              else{                       //图片未加载完成。
                  id = requestAnimFrame(render);
              }
                    }

                    proc.innerHTML = parseInt(count/len*100) + "%"; //计算得到加载的百分比
                    context.drawImage(img, 0, 0);

                }

                var requestAnimFrame = (function () { //用来做动画的。
                    return window.requestAnimationFrame ||
                            window.webkitRequestAnimationFrame ||
                            window.mozRequestAnimationFrame ||
                            window.oRequestAnimationFrame ||
                            window.msRequestAnimationFrame ||
                            function (callback) {
                                window.setTimeout(callback, 1000 / 60);
                            };
                })();

                window.cancelAnimationFrame = window[‘webkitCancelAnimationFrame‘] ||    // name has changed in Webkit
                        window[‘mozCancelRequestAnimationFrame‘] || window[‘cancelRequestAnimationFrame‘] || window[‘msCancelRequestAnimationFrame‘];
                if (!window.cancelAnimationFrame) {
                    window.cancelAnimationFrame = function (id) {
                        clearTimeout(id);
                    }
                }

            }

<div id="linten_loading" style="border:1px solid red;width:200px;">


</div>

 
时间: 2024-08-05 15:21:16

基于html5水波的加载特效的相关文章

基于jQuery点击加载动画按钮特效

分享一款基于jQuery点击加载动画按钮特效.这是一款基于jQuery+CSS3实现的鼠标点击按钮加载动画特效代码.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div class="container"> <div class="row"> <div class="col-md-6 col-md-offset-3 text-center"> <p> <button c

分享JQuery动画插件Velocity.js的六种列表加载特效

分享JQuery动画插件Velocity.js的六种列表加载特效.在这款实例中给中六种不同的列表加载效果.分别为从上飞入.从右侧飞入.从左侧飞入.和渐显.一起看下效果图: 在线预览   源码下载 实现的代码. html代码: <h1> Velocity.js <i>slice + sequence</i></h1> <pre>Only anim X number with FX#1, animate Y number with FX#2 etc

一款由jquery实现的超炫的页面加载特效

今天为大家带来一款由jquery实现的超炫的页面加载特效.连续的几个页面分开特效.最后由三维的线条由远至近消失,然后由近至远出现.效果超级梦炫.一起看下效果图: 在线预览   源码下载 实现的代码. html代码: <svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 1200 600"> <line id="uno" x1="600" y1="0

css3超炫8种loading加载特效

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Typ

使用Android新式LruCache缓存图片,基于线程池异步加载图片

import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import a

纯css3实现的动画加载特效

之前给大家带了很多款进度加载条,今天再给大家分享一款纯css3实现的动画加载特效.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div class="wrap"> <div class="curve3"> </div> <div class="curve2"> <div class="text"> 15 </div> </di

《你必须知道的.NET》读书实践:一个基于OO的万能加载器的实现

此篇已收录至<你必须知道的.Net>读书笔记目录贴,点击访问该目录可以获取更多内容. 一.关于万能加载器 简而言之,就是孝顺的小王想开发一个万能程序,可以一键式打开常见的计算机资料,例如:文档.图片和影音文件等,只需要安装一个程序就可以免去其他应用文件的管理(你让其他耗费了巨资打造的软件情何以堪...),于是就有了这个万能加载器(FileLoader). 初步分析之后,小王总结了这个万能加载器的功能点如下: (1)能够打开常见文档类资料:txt.word.pdf.visio等: (2)能够打开

基于开源框架Glide加载Gif资源图到Android ImageView中

<基于第三方开源框架Android Glide加载Gif资源图片到Android ImageView中> 通常Android的ImageView不能加载Gif图片,如不做任何处理,那么加载到ImageView中的Gif只显示第一帧.网上给出很多解决方案,也有不少开源框架定制专属的Gif View用于加载Gif图,这些解决方案基本上大多数是借助Android的Movie,把Gif图片资源作为流,解析成Android Movie显示,这些定制的基本思想就是先检测该图片资源是否是Gif图,若是,则按

HTML5 实现触摸加载数据

var startX;                     //触摸起始横坐标var startY;                    //触摸起始纵坐标var moveSpave;                //移动的距离var isMoveX = true;          //判断是否为左右移动var isFirst = true;          //是否要判断touchmove方向var beginTime=0; //监听 触摸事件    document.queryS