2017-07-17 136 views
0

我想申请启动加载微调在我的网页。 当用户点击页面时,它会加载文件并显示在网页上,用户可以通过点击刷新按钮来重新生成文件。 我想显示加载微调器,因为会有一些延迟加载文件在网页上,以及当用户点击刷新按钮,在网页中生成和加载文件。页面加载时无法显示加载图标 - 引导

的html代码:

<div ng-controller="getFileToShow"> 
    <div><button ng-click="loadData()">Refresh</button> 
     <div> 
      <object standby="loading" id="htmlFrame" ng-attr-data="{{fileName}}" type="application/pdf" width="100%" height="100%">asa 
       <iframe ng-src="{{fileName}}" width="100%" height="100%" style="border: none;"> 
        This browser does not support PDFs. Please download the PDF to view it: 
       </iframe> 
      </object> 
     </div> 

    </div> 
</div> 

JS代码:

app.controller('getFileToShow', function ($scope,MyAppService) { 
    $scope.getFileToShow = function() { 
     MyAppService.getFileToShow().then(
      function (response) { 
       $scope.fileName = response; 
      }, 
      function (errResponse) { 

      }); 
    } 
    $scope.getFileToShow(); 
}); 
//service call 
myAppService.getFileToShow = function(){ 
    var Url = myURL+'/myAppData/getFileToShow.form'; 
    $http.get(repUrl).then(
     function (response) { 
      //logic here 
     }, 
    ); 
    return deferred.promise; 
} 

我从https://www.w3schools.com/howto/howto_css_loader.asp试图

CSS:

.loader { 
    border: 16px solid #f3f3f3; /* Light grey */ 
    border-top: 16px solid #3498db; /* Blue */ 
    border-radius: 50%; 
    width: 120px; 
    height: 120px; 
    animation: spin 2s linear infinite; 
} 

@keyframes spin { 
    0% { transform: rotate(0deg); } 
    100% { transform: rotate(360deg); } 
} 

无法能够应用加载微调在我上面提到的HTML代码。任何意见将是有益的。如何在页面仍在加载时显示加载图标以显示网页上的文件(我的上面的html代码用于显示网页上的文件)。同样,当用户再次单击刷新按钮时,将需要一些时间来重新生成文件并将新创建的文件重新加载到显示旧文件的网页。

回答

0

(function($){ 
 
// preloader 
 
    $(window).ready(function(){ 
 
    $('#preloader').delay(400).fadeOut(1000); 
 
    $('#overlay').delay(400).fadeOut(1000); 
 
    }) 
 

 
}(jQuery));
body { 
 
    width: 100%; 
 
    height: 100%; 
 
    overflow: hidden; 
 
} 
 

 
.spinner { 
 
    width: 80px; 
 
    height: 80px; 
 
    border: 2px solid #f2f3f3; 
 
    border-top: solid #428bca; 
 
    border-radius: 100%; 
 
    position: absolute; 
 
    top: 0; 
 
    bottom: 0; 
 
    left: 0; 
 
    right: 0; 
 
    margin: auto; 
 
    animation: spin 1s infinite linear; 
 
} 
 

 
@keyframes spin { 
 
    from { 
 
     transform: rotate(0deg); 
 
    } 
 
    to { 
 
     transform: rotate(360deg); 
 
    } 
 
} 
 

 
#overlay { 
 
    height: 100%; 
 
    width: 100%; 
 
    background: rgba(0, 0, 0, 1); 
 
    position: absolute; 
 
    text-align: center; 
 
    left: 0; 
 
    top: 0; 
 
    bottom: 0; 
 
    right: 0; 
 
}
<!DOCTYPE html> 
 
<html lang="en"> 
 

 
<head> 
 
    <meta charset="UTF-8"> 
 
    <title>Creating A Loading Spinner</title> 
 

 
    <link rel="stylesheet" href="preloader.css"> 
 
    <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script> 
 
    <script src="preloader.js"></script> 
 
</head> 
 

 
<body> 
 

 

 
    </div> 
 
    
 
    
 
    <div id="preloader" class="spinner"></div> 
 
</body> 
 

 
</html>

这可能与装载机

HTML:

<!DOCTYPE html> 
<html lang="en"> 

<head> 
    <meta charset="UTF-8"> 
    <link rel="stylesheet" href="preloader.css"> 
    <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script> 
    <script src="preloader.js"></script> 
</head> 

<body> 

    <div id="preloader" class="spinner"></div> 
</body> 

JS:

(function($){ 
// preloader 
    $(window).ready(function(){ 
    $('#preloader').delay(400).fadeOut(1000); 
    $('#overlay').delay(400).fadeOut(1000); 
}) 

}(jQuery)); 

的CSS:

body { 
    width: 100%; 
    height: 100%; 
    overflow: hidden; 
} 

.spinner { 
    width: 80px; 
    height: 80px; 
    border: 2px solid #f2f3f3; 
    border-top: solid #428bca; 
    border-radius: 100%; 
    position: absolute; 
    top: 0; 
    bottom: 0; 
    left: 0; 
    right: 0; 
    margin: auto; 
    animation: spin 1s infinite linear; 
} 

@keyframes spin { 
    from { 
     transform: rotate(0deg); 
    } 
    to { 
     transform: rotate(360deg); 
    } 
} 

#overlay { 
    height: 100%; 
    width: 100%; 
    background: rgba(0, 0, 0, 1); 
    position: absolute; 
    text-align: center; 
    left: 0; 
    top: 0; 
    bottom: 0; 
    right: 0; 
} 
+0

@lan - 我不希望使用任何额外的jar文件。如果你看到链接https://www.w3schools.com/howto/howto_css_loader.asp它非常简单。我想用这个来实现。即使在加载页面之后,问题仍会在网页上看到微调器。如果你看到我的js代码,我检索的文件是动态的,我不能给任何超时,因为我们无法预测加载/生成文件和加载需要多长时间。 – DIM

+0

正是这就是为什么在js它说window.ready这意味着该页面已准备就绪,并且在页面加载后1000毫秒后淡出之后。 – Ian