基於html5水波的載入特效

來源:互聯網
上載者:User

標籤:des   style   blog   http   io   color   ar   os   sp   

先來看效果  圖片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>

 

 

基於html5水波的載入特效

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.