jquery獲取滾動欄裏面內容的實際高度

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
        <style>
            .box{
                width: 200px;
                height: 100px;
                border: 1px solid #ddd;
                overflow-y: scroll;
            }
        </style>
        <script>
            $(document).ready(function(){
                console.log($(".box").height());//100,獲取設置的div高度
                console.log($(".box")[0].scrollHeight)//189,獲取實際內容的高度
            })
        </script>
    </head>
    <body>
        <div class="box">
            hello
            <br />
            hello
            <br />
            hello
            <br />
            hello
            <br />
            hello
            <br />
            hello
            <br />
            hello
            <br />
            hello
            <br />
            hello
            <br />
        </div>
    </body>
</html>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章