📌  相关文章
📜  如何使用AngularJS动态获取div的内容高度?

📅  最后修改于: 2021-05-13 19:59:11             🧑  作者: Mango

div的内容高度可以根据用户要求使用clientHeight和scrollHeight属性动态获取。如果用户想知道实际显示内容所需的空间,包括填充所占用的空间,但不包括滚动条,边距或边框,则用户可以使用以下任何一种过程来返回整个内容的高度。一个元素。

  • 使用Element.clientHeight属性
  • 使用Element.scrollHeight属性

示例1:使用clientHeight属性的div的Content Height将返回元素整个内容的高度。

HTML


  

    
  
    

  

    
        

GeeksforGeeks

        

Geeting Content height

           
            Calculate content height of a div              on GeeksforGeek. GeeksforGeeks is             a computer science portal which             helps students to learn various              programming language and master             data structures and algorithms.              There are various courses available             to learn new skills.         
        
                    

    
          


HTML


  

    
  
    

  

    
        

GeeksforGeeks

        

Geeting Content height

           
            Calculate content height of a div             on GeeksforGeek. GeeksforGeeks is             a computer science portal which             helps students to learn various              programming language and master              data structures and algorithms.              There are various courses available              to learn new skills.         
        
                       

    
          


输出:

  • 之前单击按钮:

  • 单击按钮后:

示例2:使用scrollHeight属性的div的Content Height将返回元素整个内容的高度。

的HTML



  

    
  
    

  

    
        

GeeksforGeeks

        

Geeting Content height

           
            Calculate content height of a div             on GeeksforGeek. GeeksforGeeks is             a computer science portal which             helps students to learn various              programming language and master              data structures and algorithms.              There are various courses available              to learn new skills.         
        
                       

    
          

输出:

  • 之前单击按钮:

  • 单击按钮后: