ダウンロードの進捗状況を表示する、よく見かけるプログレスバーをブラウザで実現したいと思います。
- JavaScriptでサーバーにあるデータ(動画、写真等指定なし)をダウンロード
- ダウンロード状況をパーセント表示し、ダウンロード完了(100%)
- alert("ダウンロード完了");
下記URLでは、まだJSのコードが不十分で、うまく動作しません。
緑のバーがテテーン♪と進んで欲しいです。
https://jsfiddle.net/7u586411/2/
具体的な質問内容が書けず申し訳ありませんが、
ご指摘いただければ、解決に近づけるかもしれません。
頑張ります。よろしくお願いいたします。
HTML
1<div id="meter"> 2<p id="bar"><span></span></p> 3<p id="now">now loading...</p><p id="percent"></p> 4</div>
CSS
1 2#meter { 3 4 position: absolute; 5 margin: auto; 6 7 top: 0; 8 right: 0; 9 bottom: 0; 10 left: 0; 11 12 width: 200px; 13 height: 30px; 14 15 z-index: 20; 16 17 18} 19 20 21#now { 22 23 position: absolute; 24 margin: auto; 25 26 top: 25px; 27 right: 0; 28 bottom: 0; 29 left: -40; 30 31 text-align: center; 32 font-size: 15px; 33 34 font-family: arial; 35 font-weight: bold; 36 37 color: #ffffff; 38 39 z-index: 20; 40 41} 42 43#percent { 44 45 position: absolute; 46 margin: auto; 47 48 top: 25px; 49 right: 0; 50 bottom: 0; 51 left: 95; 52 53 text-align: center; 54 font-size: 15px; 55 56 font-family: arial; 57 font-weight: bold; 58 59 color: #ffffff; 60 61 z-index: 20; 62 63} 64 65 66#bar { 67 68 position: absolute; 69 margin: 0 0 0 0; 70 71 width: 200px; 72 height: 15px; 73 74 text-align: center; 75 76 border:2px solid #ffffff; 77 background: #00FF00; 78 79 -webkit-border-radius: 20px; 80 -ms-border-radius: 20px; 81 82 z-index: 20; 83 84} 85 86#bar span{ 87 88 position: absolute; 89 margin: auto; 90 float: left; 91 92 top: 0; 93 94 bottom: 0; 95 left: 0; 96 97 background: #00FF00; 98 display: block; 99 height: 15px; 100 101 102 -webkit-border-radius: 20px; 103 -ms-border-radius: 20px; 104 z-index: 20; 105 106} 107
JavaScript
1$(document).ready(function() { 2 3 var xhr = new XMLHttpRequest 4 xhr.open('GET', 'index.html'); 5 xhr.onprogress = function (evt) { 6 7 var load = (100*evt.loaded/evt.total|0); 8 $('#percent').html(load + '%'); 9 $('#bar span').css({'width': load*2}); 10 }; 11 12 xhr.send(); 13 14});

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/05 03:40
2017/07/05 03:43
2017/07/05 04:51
2017/07/05 11:52