jquery - 动画不透明度,插入 html,动画不透明度

标签 jquery animation opacity

使用我的jquery,我试图通过将消息的不透明度动画化,插入loading.gif 并将不透明度动画化回来,使从消息到加载函数的转换在眼睛上变得容易。它失败了。

$('#powerSearchSubmitButton').click(function(ev) {
    startLoad();
    return false;
});
function startLoad() {
    $('.message').each(function(i) {
        $(this).animate({opacity: 0}, 500, function() {
            $(this).html("<img src=\"/content/pics/loadingBig.gif\" alt=\"loading\" style=\"opacity:0\"/>");
            $(this).animate({opacity: 1},500);
        });
    };
    return true;
};

当我省略 .html() 调用时,它工作正常(当然图像不在那里;所以我认为这是因为 html 没有插入 opacity:0; 但是当我用 style="opacity:0" 插入它时,它无法淡入……

我做错了什么?

最佳答案

试试这个:

$(this).fadeOut(500, function() {
     $(this).html("<img src='content/pics/loadingBig.gif' alt='loading'/>");
    });
$(this).fadeIn(500);

关于jquery - 动画不透明度,插入 html,动画不透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/340232/

相关文章:

jquery - 在同一级别创建 2 个子剑道网格

javascript - ajax get,如果未找到原始网址,则使用备用网址

objective-c - iOS:简单的动画

animation - Google 如何为他们的 Logo 制作动画?

swift - 自定义幻灯片转场 - Xcode 8.0 Swift 3.0

html - CSS 中的背景图像不透明度(在 Dreamweaver 中工作)

带有渐变 mask 的 CSS 垂直滚动选框

jquery - Div 切换器 - 切换当前 div 事件描述

javascript - 使用 BootStrap 和 Angular - 动态选择输入

jQuery:如果我的 css 可见性:隐藏,我如何显示我的元素?