• 下载进度条实现思路


    html/ajax

    var url = "img/01.png";
    $.ajax({
        type: 'GET',
        dataType: 'json',
        url: url,
        cache: false,
        xhr: function() {
            var xhr = new window.XMLHttpRequest();
            //Download progress
            xhr.addEventListener("progress", function(evt) {
                if(evt.lengthComputable) {
                    var percentComplete = evt.loaded / evt.total;
                    console.log(Math.round(percentComplete * 100) + "%");
                }
    
            }, false);
            return xhr;
        },
        beforeSend: function() {},
        complete: function() {},
        success: function(result) {}
    
    });

    H5+

    var url = "";
    var options = {method: "GET"};
    dtask = plus.downloader.createDownload(url, options);
    dtask.addEventListener("statechanged", function(task, status) {
        switch(task.state) {
            case 1: // 开始  
                break;
            case 2: //已连接到服务器  
                break;
            case 3: // 已接收到数据  
                var current = parseInt(100 * task.downloadedSize / task.totalSize);
                console.log(current);
                break;
            case 4: // 下载完成  plus.notification.compProgressNotification("下载完成");//插件调用  
                plus.runtime.install(plus.io.convertLocalFileSystemURL(task.filename), //安装APP  
                    {
                        force: true
                    },
                    function() {
    
                    },
                    function() {
                        mui.toast('安装失败');
                    });
                break;
        }
    });
    dtask.start(); 

    uni.app

    https://uniapp.dcloud.io/api/request/network-file

    未完成待续

  • 相关阅读:
    PHP常用代码大全
    使用PHP CURL的POST数据
    mysql_fetch_assoc() ,mysql_fetch_array() , mysql_fetch_row()的区别
    Memcached 搭建过程
    IOS中的UIScrollView
    IOS的自定义控件
    苹果API常用英语名词
    UIActivityIndicatorView
    UIButton
    UIControl事件
  • 原文地址:https://www.cnblogs.com/liangtao999/p/12174048.html
Copyright © 2020-2023  润新知