[英]Phonegap File Transfer - how to insert a loading .gif while loading the file
我已經為我的phonegap應用程序獲得了此Javascript代碼,用於將聲音文件下載到Ringtones文件夾中。 由於下載它可能會花費很多時間,直到彈出警報,所以我想在下載文件時插入.gif。我該怎么做? 這是我的代碼:
var fileTransfer = new FileTransfer();
fileTransfer.download(
"http://example.com/Sound.mp3",
"file://sdcard/Ringtones/Sound.mp3",
function(entry) {
alert("Sound downloaded!" );
},
function(error) {
alert("download error source " + error.source);
alert("download error target " + error.target);
alert("upload error code" + error.code);
});
}
在頁面上的任意位置放置:
<div id="loadingImg" style="display:none;">
<img src="load.gif" />
</div>
然后在代碼中的相關點顯示(或隱藏)它(也許使用jQuery ):
var fileTransfer = new FileTransfer();
//Fade in the loadingImg Div at the start of your function
$("loadingImg").fadeIn();
fileTransfer.download(
"http://example.com/Sound.mp3",
"file://sdcard/Ringtones/Sound.mp3",
function(entry) {
//Fade out the loadingImg Div on success
$("loadingImg").fadeOut();
alert("Sound downloaded!");
},
function(error) {
//Fade out the loadingImg Div on error
$("loadingImg").fadeOut();
alert("download error source " + error.source);
alert("download error target " + error.target);
alert("upload error code" + error.code);
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.