• h5+ 实时网速


    var nowsize="";记录上次下载数据包大小
    var st=new Date()记录上次刷新进度条时间

     1 case 3:
     2                                 var et=new Date() 
     3                                 var current = parseInt(100 * task.downloadedSize / task.totalSize);
     4                                 // plus.notification.setProgress(current); //插件调用
     5                                 document.getElementById("jdt").style.display="";  
     6                                 document.getElementById("jdt").style.width=current+'%';
     7                                 if(((et-st)/1000)>1){
     8                                     document.getElementById("jdt").innerText=current+'%'+"|"+changeSize((1000*(task.downloadedSize-nowsize))/(et-st))+"/s";
     9                                     nowsize=task.downloadedSize;   
    10                                     st=new Date(); 
    11                                 } 
    12                                 break;
    View Code

    网络速度转换

     1         function changeSize(size) {
     2                 var num;
     3                 if((size / 1024) <= 1024) {
     4                     num = size / 1024;
     5                     return num.toFixed(2) + 'KB';
     6                 }
     7                 else if((size / 1024) > 1024 && (size / 1024) <= (1024 * 1024)) {
     8                     num = (size / 1024) / 1024;
     9                     return num.toFixed(2) + 'M';
    10                 }
    11                 else if((size / 1024) > (1024 * 1024)) {
    12                     num = ((size / 1024) / 1024) / 1024
    13                     return num.toFixed(2) + 'G';
    14                 }
    15                 else{
    16                     return size + 'B'; 
    17                 }
    18         } 
  • 相关阅读:
    LeetCode 12. Integer to Roman
    个人博客09
    个人博客08
    人机交互之我的输入法
    学习进度条(第六周)
    《梦断代码》阅读笔记02
    个人博客07
    学习进度条(第五周)
    个人博客06
    个人博客05
  • 原文地址:https://www.cnblogs.com/yeyuqian/p/12852092.html
Copyright © 2020-2023  润新知