Javascript Phonegap文件传输-如何在加载文件时插入加载.gif文件
我已经为我的phonegap应用程序准备了Javascript代码,用于将声音文件下载到Ringtones文件夹中。由于下载时可能需要较长时间,直到弹出警报,因此我希望在下载文件时插入.gif。。我该怎么做?这是我的代码:Javascript Phonegap文件传输-如何在加载文件时插入加载.gif文件,javascript,cordova,file-transfer,Javascript,Cordova,File Transfer,我已经为我的phonegap应用程序准备了Javascript代码,用于将声音文件下载到Ringtones文件夹中。由于下载时可能需要较长时间,直到弹出警报,因此我希望在下载文件时插入.gif。。我该怎么做?这是我的代码: var fileTransfer = new FileTransfer(); fileTransfer.download( "http://example.com/Sound.mp3", "file://sdcard/Ringtones/Sound.mp3", functio
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>
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);
});
}