简体   繁体   English

在两个带有衰落的div之间切换的最佳方法是什么?

[英]What's the best way to switch between two divs with fading?

I call those functions on href: 我在href上调用这些函数:

function LoadDiv1() {
       var uri = '@this.Routes().Parts.Div1.FullUrl(Model.SignedInUser.User.Id)';
       $('#home_content').load(uri).css("display", "none").fadeIn(500);
}
function LoadDiv2() {
       var uri = '@this.Routes().Parts.Div2.FullUrl(Model.SignedInUser.User.Id)';
       uri = uri.replace('amp;', '');
       $('#home_content').load(uri).css("display", "none").fadeIn(500);
}

They switch correctly, but every time i switch to another div, first of all i get current div loaded again, and then switched to another. 它们可以正确切换,但是每次我切换到另一个div时,首先我会再次加载当前的div,然后再切换到另一个。 It looks like delay. 看起来有点延迟。

You're making an asynchronous call to the server but the methods in the chain are executed immediately. 您正在对服务器进行异步调用,但是链中的方法会立即执行。 The div's contents are updated only later when the data has been loaded from the server. 仅当从服务器加载数据后,才更新div的内容。 You must add the fadein method to the callback function of the Ajax call so that it executes only after the contents have been updated. 您必须将Fadein方法添加到Ajax调用的回调函数中,以便仅在内容更新后才执行。

$('#home_content').css("display", "none").load( uri, 
    function() { $( '#home_content' ).fadeIn(500) } );

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

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