简体   繁体   English

Font-Awesome - 图标旋转在隐藏然后显示时不旋转

[英]Font-Awesome - icon-spin does not spin when hidden and then displayed

When my page loads, I hide the icon-refresh + icon-spin icon by setting its display property to none. 当我的页面加载时,我通过将其display属性设置为none来隐藏icon-refresh + icon-spin图标。

Now, after some action is performed, I wish to display this icon. 现在,在执行某些操作后,我希望显示此图标。 I invoke jQuery's .show() method on the icon. 我在图标上调用了jQuery的.show()方法。 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 编辑:如果从标题中不清楚,我使用Font Awesome来显示图标

You have to use $element.css("display","inline-block"); 你必须使用$element.css("display","inline-block"); instead of .show(); 而不是.show();

Old topic, but I had similar issue with "fa-spin" not working after the containing element was hidden with { visibility: hidden }, set with jQuery. 旧的主题,但是在使用jQuery设置的{visibility:hidden}隐藏了包含元素之后,我遇到了类似的问题,“fa-spin”无效。 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. 因此,删除“fa-spin”,然后以一小段延迟将其添加回来,使其按照我的需要工作。

Are you calling "$('#mySpinnerElement').hide()? 你在调用“$('#mySpinnerElement')。hide()?

I changed that to document.getElementById('mySpinnerElement').style.display = 'none'; 我将其更改为document.getElementById('mySpinnerElement')。style.display ='none';

and my spinner spins on subsequent calls 我的旋转器在随后的呼叫中旋转

HTH HTH

Swampy 沼泽的

Seems that IE10 does not run the spin animation if the initial display state is none . 似乎IE10在初始显示状态为none不运行旋转动画。 I found that dynamically changing the display to inline-block did not trigger the spin animation. 我发现动态地将显示更改为inline-block并没有触发旋转动画。 Moving the spinner off-screen solved the problem. 将微调器移出屏幕解决了这个问题。 Eg: 例如:

.icon-spinner {
    position: absolute;
    left: -9999px;
}
.is-pending .icon-spinner {
    left: 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM