简体   繁体   English

Scroll Top =滚动高度在Chrome中不起作用

[英]Scroll Top = Scroll Height not working in Chrome

This is the js that I have in my js file 这是我的js文件中包含的js

function refreshChat()
    {
        //speed up by selecting the div only once
        var shoutbox = $("#shoutbox");

        //get the height of the scroll (if any)
        var oldScrollH = shoutbox.attr("scrollHeight") - 20;

        //the ajax request
        $.ajax({
        url: 'shoutbox/update.php',
        //disable cache
        cache: false,
        success: function(html) {
            //update the shoutbox
            shoutbox.html(html);
            //get the heigth of the scroll after the update
            var newScrollH = shoutbox.attr("scrollHeight") - 20;
            if(newScrollH > oldScrollH)
            {
                //*move* the scroll down using an animation :)
                shoutbox.animate({scrollTop: newScrollH}, 1);
            }
        }   
        });
    }
    //set the refreshChat function to run every *refreshSeconds*
    setInterval(refreshChat, refreshSeconds);


});

it works fine in Firefox and IE, but with Google Chrome it constantly flicks. 它在Firefox和IE中都可以正常运行,但是在Google Chrome浏览器中,它会不断滑动。 It will scroll to the bottom on page load, but when it calls to the function refreshChat it moves back up about halfway up the div. 它将在页面加载时滚动到底部,但是当调用函数refreshChat它将向后移至div的大约一半。

I also have this in my <head> 我的<head>也有这个

$(document).ready(function(){
        //speed up by selecting the div only once
        var shoutbox = $("#shoutbox");

        //get the height of the scroll (if any)
        var oldScrollH = shoutbox.attr("scrollHeight");

        //the ajax request
        $.ajax({
        url: 'shoutbox/update.php',
        //disable cache
        cache: false,
        success: function(html) {
            //update the shoutbox
            shoutbox.html(html);
            //get the heigth of the scroll after the update
            var newScrollH = shoutbox.attr("scrollHeight");
            if(newScrollH > oldScrollH)
            {
                //*move* the scroll down using an animation :)
                shoutbox.animate({scrollTop: newScrollH}, 1);
            }
        }   
        })
        });

so that it will auto load the shoutbox on page load, could this be conflicting with it? 以便它会在页面加载时自动加载shoutbox,这是否可能与此冲突? It seems logical, but I don't want users to have to wait 3 seconds for the shoutbox to initially load. 这似乎合乎逻辑,但是我不希望用户必须等待3秒才能将shoutbox初始加载。

You need to convert string to int. 您需要将字符串转换为int。

scrollHeight is custom attribute and i guess its dynamically added so it must string thats why you need to cast it to int. scrollHeight是自定义属性,我猜它是动态添加的,因此它必须为字符串,这就是为什么需要将其强制转换为int的原因。

parseInt(shoutbox.attr("scrollHeight"));

try this, hope this will solve it. 试试这个,希望能解决。

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

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