This is happening because a Gif requires the thread to be open to display the next image. If you were using a pure css approach you would not see this issue. Take font-awesome for example -
<i class="icon-spin icon-spinner"></i>
Because this is a pure CSS approach the spinner will continue to spin even when the thread bogs down loading all of of your new records and associating their related entities.
If you need to continue spinning I would highly including this bit of CSS from the Font-Awesome source -
@-moz-keyframes spin {
0% {
-moz-transform: rotate(0deg); }
100% {
-moz-transform: rotate(359deg); } }
@-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg); }
100% {
-webkit-transform: rotate(359deg); } }
@-o-keyframes spin {
0% {
-o-transform: rotate(0deg); }
100% {
-o-transform: rotate(359deg); } }
@-ms-keyframes spin {
0% {
-ms-transform: rotate(0deg); }
100% {
-ms-transform: rotate(359deg); } }
@keyframes spin {
0% {
transform: rotate(0deg); }
100% {
transform: rotate(359deg); } }
.icon-spin {
display: inline-block;
-moz-animation: spin 2s infinite linear;
-o-animation: spin 2s infinite linear;
-webkit-animation: spin 2s infinite linear;
animation: spin 2s infinite linear; }
And using either a static icon, image or sprite and just applying class of 'icon-spin' to it, regardless of whether it is an icon or not.
Edit
Add this wherever you are declaring your CSS -
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
Change this -
<div id="showSpin" data-bind="visible: isSpinning" style="padding: 10px; position: absolute; top:248px;left: 320px; background-color: #FFF; opacity: 0.9; filter: alpha(opacity=90);">
<img src="/images/spin.gif" />
</div>
to this -
<div id="showSpin" data-bind="visible: isSpinning" style="padding: 10px; position: absolute; top:248px;left: 320px; background-color: #FFF; opacity: 0.9; filter: alpha(opacity=90);">
<i class="fa fa-spinner fa-spin"></i>
</div>
The reason it is fa
instead of icon
is the current version of FontAwesome changed to use fa instead of icon due to collisions
Last Edit
Your problem now is that your logic is faulty. I have tried to explain this in comments but I will give one last update with EXACTLY how your logic should look if you want to show your spinner and have it spinning.
isSpinning(true)
context.getData(name, records).then(function (data) {
isLoading(false);
setTimeout(function () {
isSpinning(false);
}, 1000);
})
.fail("Record not found");
<div id="showSpin" data-bind="visible: isSpinning" style="padding: 10px; position: absolute; top:248px;left: 320px; background-color: #FFF; opacity: 0.9; filter: alpha(opacity=90);">
<!-- THERE IS NO REASON TO USE A VISIBLE BINDING HERE AND ON THE PARENT -->
<i class="fa fa-2x fa-spinner fa-spin"></i>
</div>
The reason this wasn't working is in your logic. Copy this EXACTLY to your solution and it will work.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…