国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

首頁 > web前端 > H5教程 > 正文

HTML5實現(xiàn)的Loading緩沖效果

php中文網(wǎng)
發(fā)布: 2016-05-17 09:09:06
原創(chuàng)
3951人瀏覽過

? ? ? ?HTML5在移動設備上表現(xiàn),相信已經(jīng)不用我多說了,干掉了Flash之后,它已經(jīng)坐上了移動應用程序的第一把交椅。幾乎所有稍微高端一點的設備(喬幫主的iPad,iPhone和Andriod的平板手機等)的瀏覽器都支持HTML5,而且據(jù)權威人士測試,這些支持HTML5的設備對Canvas標簽的支持也是相當?shù)暮谩?br>
? ? ? ??大家都知道Web2.0以來,應用程序的實現(xiàn)使用了大量Ajax,而Loading的小圖標也有很多,甚至還有專門提供Loading圖片的網(wǎng)站,所以我就想能不能讓HTML5一并解決這個以前用gif文件才能解決的問題。出乎我意料的是,實現(xiàn)的過程非常簡單,只用了不到一小時的時間我就用HTML5實驗出了兩個Loading效果,而且這樣做出來的Loading圖標是可定制的,既可以定制顏色,也可以定制大小等屬性。

? ? ? ??第一個帶著小尾巴轉動的loading圖標畫圖的思路是,首先畫一個圓,然后在圓的邊上按順序畫大小逐漸減小的小圓點,在每次刷新畫布時改變這一系列的小圓點在大圓邊上的位置。

? ? ? ??這里是案例的演示代碼:



  1. ??
  2. ? ?
  3. ? ?loading
  4. ? ?
  5. ? ? function loading(canvas,options){
  6. ? ?? ?this.canvas = canvas;
  7. ? ?? ?if(options){
  8. ? ?? ???this.radius = options.radius||12;
  9. ? ?? ???this.circleLineWidth = options.circleLineWidth||4;
  10. ? ?? ???this.circleColor = options.circleColor||'lightgray';
  11. ? ?? ???this.dotColor = options.dotColor||'gray';
  12. ? ?? ?}else{
  13. ? ?? ???this.radius = 12;
  14. ? ?? ???this.circelLineWidth = 4;
  15. ? ?? ???this.circleColor = 'lightgray';
  16. ? ?? ???this.dotColor = 'gray';
  17. ? ?? ?}
  18. ? ? }
  19. ? ? loading.prototype = {
  20. ? ?? ?show:function (){
  21. ? ?? ???var canvas = this.canvas;
  22. ? ?? ???if(!canvas.getContext)return;
  23. ? ?? ???if(canvas.__loading)return;
  24. ? ?? ???canvas.__loading = this;
  25. ? ?? ???var ctx = canvas.getContext('2d');
  26. ? ?? ???var radius = this.radius;
  27. ? ?? ???var rotators = [{angle:0,radius:1.5},{angle:3/radius,radius:2},{angle:7/radius,radius:2.5},{angle:12/radius,radius:3}];
  28. ? ?? ???var me = this;
  29. ? ?? ???canvas.loadingInterval = setInterval(function(){
  30. ? ?? ?? ? ctx.clearRect(0,0,canvas.width,canvas.height);
  31. ? ?? ?? ? var lineWidth = me.circleLineWidth;
  32. ? ?? ?? ? var center = {x:canvas.width/2 - radius,y:canvas.height/2-radius};
  33. ? ?? ?? ? ctx.beginPath();
  34. ? ?? ?? ? ctx.lineWidth = lineWidth;
  35. ? ?? ?? ? ctx.strokeStyle = me.circleColor;
  36. ? ?? ?? ? ctx.arc(center.x,center.y,radius,0,Math.PI*2);
  37. ? ?? ?? ? ctx.closePath();
  38. ? ?? ?? ? ctx.stroke();
  39. ? ?? ?? ? for(var i=0;i
  40. ? ?? ?? ?? ?var rotatorAngle = rotators[i].currentAngle||rotators[i].angle;
  41. ? ?? ?? ?? ?//在圓圈上面畫小圓
  42. ? ?? ?? ?? ?var rotatorCenter = {x:center.x-(radius)*Math.cos(rotatorAngle) ,y:center.y-(radius)*Math.sin(rotatorAngle)};
  43. ? ?? ?? ?? ?var rotatorRadius = rotators[i].radius;
  44. ? ?? ?? ?? ?ctx.beginPath();
  45. ? ?? ?? ?? ?ctx.fillStyle = me.dotColor;
  46. ? ?? ?? ?? ?ctx.arc(rotatorCenter.x,rotatorCenter.y,rotatorRadius,0,Math.PI*2);
  47. ? ?? ?? ?? ?ctx.closePath();
  48. ? ?? ?? ?? ?ctx.fill();
  49. ? ?? ?? ?? ?rotators[i].currentAngle = rotatorAngle+4/radius;
  50. ? ?? ?? ? }
  51. ? ?? ???},50);
  52. ? ?? ?},
  53. ? ?? ?hide:function(){
  54. ? ?? ???var canvas = this.canvas;
  55. ? ?? ???canvas.__loading = false;
  56. ? ?? ???if(canvas.loadingInterval){
  57. ? ?? ?? ? window.clearInterval(canvas.loadingInterval);
  58. ? ?? ???}
  59. ? ?? ???var ctx = canvas.getContext('2d');
  60. ? ?? ???if(ctx)ctx.clearRect(0,0,canvas.width,canvas.height);
  61. ? ?? ?}
  62. ? ? };
  63. ? ?
  64. ??
  65. ??
  66. ? ?
  67. ? ?


  68. ? ?
  69. ? ?

  70. ? ?


  71. ? ? <script><br> </script>
  72. ? ? var loadingObj = new loading(document.getElementById('canvas'),{radius:8,circleLineWidth:3});
  73. ? ? loadingObj.show();
  74. ? ?
  75. ??
復制代碼


? ? ? ??演示地址:http://f200-8.bbs.hexun.com/e/111219/loading.htm

? ? ? ??第二個較為簡單,在一個圓環(huán)上有一個相同圓心相同半徑的圓弧在不停的轉動。畫圖的步驟是首先畫一個圓環(huán),然后畫一個不同顏色相同圓心半徑的圓弧,在每次刷新畫布時改變圓弧的起始角度。

? ? ? ??這里是案例的演示代碼:




  1. ??
  2. ??loading
  3. ??<script><br> </script>
  4. ? ?/*
  5. ? ? html5 loading 鎺т歡
  6. ? ? 浣滆
HTML速學教程(入門課程)
HTML速學教程(入門課程)

HTML怎么學習?HTML怎么入門?HTML在哪學?HTML怎么學才快?不用擔心,這里為大家提供了HTML速學教程(入門課程),有需要的小伙伴保存下載就能學習啦!

下載
來源:php中文網(wǎng)
本文內容由網(wǎng)友自發(fā)貢獻,版權歸原作者所有,本站不承擔相應法律責任。如您發(fā)現(xiàn)有涉嫌抄襲侵權的內容,請聯(lián)系admin@php.cn
最新問題
開源免費商場系統(tǒng)廣告
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板
關于我們 免責申明 意見反饋 講師合作 廣告合作 最新更新
php中文網(wǎng):公益在線php培訓,幫助PHP學習者快速成長!
關注服務號 技術交流群
PHP中文網(wǎng)訂閱號
每天精選資源文章推送
PHP中文網(wǎng)APP
隨時隨地碎片化學習
PHP中文網(wǎng)抖音號
發(fā)現(xiàn)有趣的

Copyright 2014-2025 http://m.miracleart.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號