Loading spinner gif image gets stuck

≡放荡痞女 提交于 2019-12-20 03:30:11

问题


I have a 6kb animated gif loading spinner. when I open it in a browser window, it spins fine. But when it opens on an ajax call on my web page, it is stuck. It appears ontime and disappears ontime, but does not spin.

Any ideas?

Here is the jQuery code:

        $('#please-wait')
        .css("visibility", "visible")//.hide()
        .ajaxStart(function() {
            $(this).css("visibility", "visible");
        })
        .ajaxStop(function() {
            $(this).css("visibility", "hidden");
        });

or

        $('#please-wait')
        .show()
        .ajaxStart(function() {
            $(this).show();            
        })
        .ajaxStop(function() {
            $(this).hide();
        });

any ideas?


回答1:


Here is a jsfiddle example of how it should or could be done.

Here's a snippet

$('#start_loading').click(function(){
    $('#display').html('<img src="http://thinkfuture.com/wp-content/uploads/2013/10/loading_spinner.gif" />');
    setTimeout(function(){
        $('#display').html($('#content').html());
    }, 1000);
});

$('#reset').click(function(){
    $('#display').html('');
});
body{
  background-color: white;
}

#content{
    display:none;
}

#display{
    margin-top: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://code.jquery.com/jquery-1.6.3.min.js" type="text/javascript"></script>  
<button id='start_loading'>Load text</button>
<button id='reset'>Reset</button>

<div id='display'>
</div>

<div id='content'>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin risus ipsum, hendrerit vitae facilisis sit amet, viverra sit amet elit. Nullam interdum sodales tortor quis suscipit. Donec facilisis condimentum sodales. Nunc imperdiet vehicula aliquam. Etiam non ligula enim, non euismod dui. Aliquam in fermentum neque. Praesent auctor lectus eu magna gravida convallis. Donec semper hendrerit porta. In feugiat tellus a purus vulputate adipiscing. Aenean et risus nec nisl auctor scelerisque. Duis eleifend nunc ut odio consectetur scelerisque.</p><br/>

    <p>Aliquam in scelerisque erat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aenean dignissim orci at quam placerat a placerat sem porta. Nulla facilisi. Ut ligula lorem, faucibus sit amet eleifend id, fringilla ut orci. Aliquam viverra, enim a auctor tincidunt, neque dui sollicitudin enim, eget feugiat odio lacus cursus lacus. Nunc risus urna, elementum eu vehicula in, fringilla et ante. Aenean iaculis volutpat purus, vitae faucibus justo auctor at. Integer non fringilla nibh.</p><br/>

<p>Quisque elementum, sapien in viverra mollis, magna nisl blandit tortor, ut tincidunt risus nulla id nunc. Fusce rutrum elementum mauris, id aliquam magna varius sed. Ut vestibulum elementum sapien et sagittis. Vestibulum vitae sem arcu. Nulla lacus dui, lacinia vitae dapibus ac, tincidunt vel lectus. In hac habitasse platea dictumst. Curabitur interdum ullamcorper odio, ullamcorper mollis ligula auctor eget. Donec aliquet arcu sed est dignissim pharetra. Praesent sit amet dui venenatis nisl ullamcorper convallis. Morbi rutrum neque id dui venenatis et bibendum felis placerat. </p>
</div>

If you're doing the right parts of JQuery then the odds are your .gif doesn't have a repeat cycle, meaning it only animates once. Since you only hide it instead of adding/removing, it doesn't reset the animation.



来源:https://stackoverflow.com/questions/7440897/loading-spinner-gif-image-gets-stuck

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!