zoukankan      html  css  js  c++  java
  • 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         } 
  • 相关阅读:
    java值类型和引用类型
    0513作业
    随机四位验证码
    1-36随机生成6个不重复的数
    java随机数
    0509作业
    作业0508
    字符集
    eclipse快捷键
    数据类型 转换
  • 原文地址:https://www.cnblogs.com/yeyuqian/p/12852092.html
Copyright © 2011-2022 走看看