jQuery 使我的 ajax 更新 div 淡入

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/183638/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 08:45:25  来源:igfitidea点击:

Making my ajax updated div fade in

jqueryajax

提问by Chris J Allen

I have this code that performs an ajax call and loads the results into two duplicate divs every time a dropdown is changed. I want the results to be faded into the div, to give a more obvious indication that something has changed, as its so seamless its sometimes hard to notice the change!

我有这段代码,每次更改下拉列表时,都会执行 ajax 调用并将结果加载到两个重复的 div 中。我希望结果淡入 div 中,以更明显地表明某些事情发生了变化,因为它是如此无缝,有时很难注意到变化!

print("$('.ajaxdropdown').change(function(){


        $.ajax({
            type: "GET",
            url: "/includes/html/gsm-tariff.php",
            data: "c_name="+escape($(this).val()),
            success: function(html){
                $("#charges-gsm").html(html);
                                    //i want to fade result into these 2 divs...
                $("#charges-gsm-faq").html(html);
                $("#charges-gsm-prices").html(html);
            }
        });
    });");

I've tried appending the fadein method and a few other things, but no joy.

我试过追加淡入淡出方法和其他一些东西,但没有快乐。

回答by Adam Bellaire

You'll have to hide()it before you can use fadeIn().

你必须hide()它才可以使用fadeIn()

UPDATE:Here's how you'd do this by chaining:

更新:这是通过链接来执行此操作的方法:

$("#charges-gsm-faq").hide().html(html).fadeIn();
$("#charges-gsm-prices").hide().html(html).fadeIn();

回答by Adam Bellaire

You could also leave it visible and just make it transparent, and then fade it to full opacity, using:

您也可以让它可见并使其透明,然后使用以下方法将其淡化至完全不透明:

... .css({ opacity: 0 }).fadeTo("normal",1);

回答by kingr

You'll have to hide() it before you can use fadeIn()

在使用fadeIn() 之前,您必须先隐藏() 它

Above worked for me

以上为我工作

回答by Brynner Ferreira

It works with load():

它与 load() 一起使用:

$('.element').load('file.html').hide().fadeIn();

回答by Malfist

JQuery.ui has a bunch of different things you can do with effects. You can find them here: http://docs.jquery.com/Effects

JQuery.ui 有很多不同的事情你可以用效果来做。你可以在这里找到它们:http: //docs.jquery.com/Effects