PHP Curl进度条(回调返回百分比)
发布时间:2020-12-13 17:05:40 所属栏目:PHP教程 来源:网络整理
导读:我已经使用了curl进度条 curl_setopt($curl,CURLOPT_PROGRESSFUNCTION,'callback');curl_setopt($curl,CURLOPT_BUFFERSIZE,64000);curl_setopt($curl,CURLOPT_FOLLOWLOCATION,true); 和回调函数. 问题是,脚本每次都输出我的html上的百分比,如下所示: 00.10.
我已经使用了curl进度条
curl_setopt($curl,CURLOPT_PROGRESSFUNCTION,'callback'); curl_setopt($curl,CURLOPT_BUFFERSIZE,64000); curl_setopt($curl,CURLOPT_FOLLOWLOCATION,true); 和回调函数. 问题是,脚本每次都输出我的html上的百分比,如下所示: 0 0.1 0.2 0.2 0.3 0.4 .. .. .. 1 1.1 如何将其与CSS结合使用以显示不断变化的进度条? 解决方法
假设您有一个进度条HTML:
<div id="progress-bar"> <div id="progress">0%</div> </div> CSS: #progress-bar { width: 200px; padding: 2px; border: 2px solid #aaa; background: #fff; } #progress { background: #000; color: #fff; overflow: hidden; white-space: nowrap; padding: 5px 0; text-indent: 5px; width: 0%; } 和JavaScript: var progressElement = document.getElementById('progress') function updateProgress(percentage) { progressElement.style.width = percentage + '%'; progressElement.innerHTML = percentage + '%'; } 您可以输出JavaScript并让它为您更新进度条,例如: <script>updateProgress(0);</script> <script>updateProgress(0.1);</script> <script>updateProgress(0.2);</script> .. .. 请注意,您不能将每个更新放在单独的脚本块中,因为浏览器将在执行前尝试读取完整脚本,并且进度条将不起作用. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |