在进度条中传递页面加载时间

Passing page loading time in progress bar

本文关键字:加载 时间      更新时间:2023-09-26

我在我的页面有进度条。它应该得到显示,直到页面完全加载。所以我希望我的进度条显示在页面上等于页面加载时间。因此,我尝试获得页面加载时间并通过该时间值来显示进度条。我已经完成了编码

<script type="text/javascript">
    var startTime = new Date().getTime();
    var loadTime;
    function pageload() {
        var endTime = new Date().getTime();
        loadTime = endTime - startTime;
        // alert(loadTime);
    }
    window.onload = function () { pageload(); }
    jQuery(document).ready(function () {
        jQuery('#container').showLoading(
             {
                 'afterShow':
                function () {
                    var a = loadTime;
                    setTimeout("jQuery('#container').hideLoading()", a);
                }
             });
    });
</script>

<script type="text/javascript">
    var startTime = new Date().getTime();
    var loadTime;
    function pageload() {
        var endTime = new Date().getTime();
        loadTime = endTime - startTime;
        setTimeout("jQuery('#container').hideLoading()", loadTime);
        // alert(loadTime);
    }
    window.onload = function () { pageload(); }
    jQuery(document).ready(function () {
        jQuery('#container').showLoading();
    });
</script>

我可能错了,但我认为你只是想隐藏它在onLoad,像这样:

jQuery(document).onload(function(){
    jQuery('#container').hideLoading();
});

将其放在pageload()函数中:

function pageload() {
    var endTime = new Date().getTime();
    loadTime = endTime - startTime;
    jQuery('#container').hideLoading();
}