[英]Phonegap File Transfer - how to insert a loading .gif while loading the file
I've got this Javascript code for my phonegap application for downloading a soundfile into the Ringtones folder. 我已经为我的phonegap应用程序获得了此Javascript代码,用于将声音文件下载到Ringtones文件夹中。 Since it can take while downloading it and until the alert pops up, I'd like to insert a .gif while the file is downloading.. How can i do this?
由于下载它可能会花费很多时间,直到弹出警报,所以我想在下载文件时插入.gif。我该怎么做? This is my code:
这是我的代码:
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);
});
}
Have this where you want on your page: 在页面上的任意位置放置:
<div id="loadingImg" style="display:none;">
<img src="load.gif" />
</div>
then display/hide it at relevant points in your code (perhaps using jQuery ): 然后在代码中的相关点显示(或隐藏)它(也许使用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.