Font-Awesome - icon-spin does not spin when hidden and then displayed
Asked Answered
W

5

18

When my page loads, I hide the icon-refresh + icon-spin icon by setting its display property to none.

Now, after some action is performed, I wish to display this icon. I invoke jQuery's .show() method on the icon. However, while the icon is shown, the icon is not spinning anymore.

If I load it without hiding it initially, it spins. But not when it is hidden and displayed later.

EDIT: If it was not clear from the title, I am using Font Awesome to display the icons

Wallah answered 11/4, 2013 at 20:5 Comment(2)
This seems to work for me: jsfiddle.net/RXkwq (JSFiddle WebFont issues not withstanding)Marcmarcano
I've got the same problem. Only occurs in Firefox 35. The answer below didn't solve it for meSeptivalent
K
29

You have to use $element.css("display","inline-block"); instead of .show();

Kagu answered 1/7, 2013 at 11:26 Comment(2)
This fixes it in Safari and Firefox for me. It was previously working in Chrome. I've not tested anything else yet…Ophidian
in case anyone wondering .show() sets display:inline which does not support css transform. see #14883750Denier
C
1

Old topic, but I had similar issue with "fa-spin" not working after the containing element was hidden with { visibility: hidden }, set with jQuery. There was also some other animation involve, which was probably causing timing issues, etc.

The fix was to set an event on the containing element to fire on making it visible again, which fired this function:

ply_obj.container.on(
            'controlsshown',
            function () {

                if (ply_obj.config.loop_tf) {
                    ply_obj.loop_icon.removeClass('fa-spin');
                    setTimeout(function () { ply_obj.loop_icon.addClass('fa-spin'); }, 100);
                }
            }
        );

So removing the "fa-spin", then adding it back with a small delay made it work as desired for me.

Counterpoise answered 4/12, 2015 at 16:18 Comment(0)
O
0

Are you calling "$('#mySpinnerElement').hide()?

I changed that to document.getElementById('mySpinnerElement').style.display = 'none';

and my spinner spins on subsequent calls

HTH

Swampy

Organzine answered 27/5, 2013 at 12:8 Comment(0)
D
0

Seems that IE10 does not run the spin animation if the initial display state is none. I found that dynamically changing the display to inline-block did not trigger the spin animation. Moving the spinner off-screen solved the problem. E.g:

.icon-spinner {
    position: absolute;
    left: -9999px;
}
.is-pending .icon-spinner {
    left: 0;
}
Dentation answered 3/3, 2014 at 10:37 Comment(0)
Q
0

Put your icon in div or span tag and hide and show that tag not the icon.

HTML Code:

 <span class="ig-icon-loading"><i class="fa fa-spin fa-spinner"></i></span>

jQuery:

$('.ig-icon-loading').show();

CSS:

.ig-icon-loading{
    display: none;
}
Quotha answered 24/12, 2023 at 8:44 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.