Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 每次刷新时滚动到div的底部_Html_Scroll_Refresh - Fatal编程技术网

Html 每次刷新时滚动到div的底部

Html 每次刷新时滚动到div的底部,html,scroll,refresh,Html,Scroll,Refresh,目前,我有一个div,每8秒刷新一次。这个div基本上加载一个php页面。 然而,我面临一个问题,滚动到这一页的底部。 这是刷新和滚动到div底部的代码: <script> var refreshId = setInterval(function() { $('#responsecontainer').fadeOut("slow").load('forum.php').fadeIn("slow"); $(

目前,我有一个div,每8秒刷新一次。这个div基本上加载一个php页面。 然而,我面临一个问题,滚动到这一页的底部。 这是刷新和滚动到div底部的代码:

 <script>
    var refreshId = setInterval(function()
    {            
         $('#responsecontainer').fadeOut("slow").load('forum.php').fadeIn("slow");

         $('#chat').attr({ scrollTop: $('#chat').attr("scrollHeight") });
    }, 8000);

    </script>

var refreshId=setInterval(函数()
{            
$(“#responsecontainer”).fadeOut(“慢”).load('forum.php').fadeIn(“慢”);
$('#chat').attr({scrollTop:$('#chat').attr(“scrollHeight”)});
}, 8000);
div容器代码如下所示:

<div style="width: 100%; height: 300px; overflow: scroll; border: 5px ; background-color:#ccc ;" id="responsecontainer" name="chat">

            Loading..

 </div>

加载。。

请建议我如何在刷新div时转到div的底部。谢谢

加载文档时应调用脚本。然后使用淡出和淡出动画将在加载后发生,因此它会重置滚动位置。下面的脚本将工作,但最终没有这些动画

load方法是一个XHR调用,它返回响应状态,使用它我们可以控制显示的数据

$(document).ready(function() {
var refreshId = setInterval(function() {            
    $('#responsecontainer').load('forum.php', function(response, status, xhr) {
        if (status == "error") {
            var msg = "Sorry but there was an error: ";
            $("#error").html(msg + xhr.status + " " + xhr.statusText);
        }
        else{
            $('#responsecontainer').scrollTop($('#responsecontainer').height());        
        }
    });
}, 8000);
});

加载文档时应调用脚本。然后使用淡出和淡出动画将在加载后发生,因此它会重置滚动位置。下面的脚本将工作,但最终没有这些动画

load方法是一个XHR调用,它返回响应状态,使用它我们可以控制显示的数据

$(document).ready(function() {
var refreshId = setInterval(function() {            
    $('#responsecontainer').load('forum.php', function(response, status, xhr) {
        if (status == "error") {
            var msg = "Sorry but there was an error: ";
            $("#error").html(msg + xhr.status + " " + xhr.statusText);
        }
        else{
            $('#responsecontainer').scrollTop($('#responsecontainer').height());        
        }
    });
}, 8000);
});