문제

I am using this function to refresh a part of my page, but the problem is that it's loading the ul#bla twice, which forces the list to change position by going to the right.

How can I use this function to replace ul#bla with itself? By using replaceWith? If so, how? I can't get it working

jQuery(document).ready(function() {
    var refreshId = setInterval(function()
    {
        jQuery('ul#bla').fadeOut("fast").load("testpage.php ul#bla").fadeIn("fast");
    }, 2000);

});
도움이 되었습니까?

해결책

How about:

jQuery(document).ready(function() {
    var refreshId = setInterval(function() {
        jQuery('ul#bla').fadeOut("fast", function () {
            jQuery(this).load("testpage.php ul#bla", function () {
                jQuery(this).fadeIn("fast");
            });
        });
    }, 2000);
});

fadeIn(), fadeOut() and load() are sync in jQuery so you need to place them in callback of each other.

다른 팁

Try to empty the container before loading again.

$(function() 
{
    var refreshId = setInterval(function()
    {
        var $container = $('ul#bla');

        $container.fadeOut("fast");
        $container.empty();
        $container.load("testpage.php ul#bla");
        $container.fadeIn("fast");

    }, 2000);

});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top