How to judge text-overflow: ellipsis (whether it overflows) (posted)

Source address: http://blog.csdn.net/fb_01/article/details/51345595

 

1. The ellipsis is often used when a single line of text exceeds. How to judge whether the text exceeds?

 

[html]  view plain copy  
 
  1. <html>  
  2. <head>  
  3. <metahttp-equiv="Content-Type"content="text/html; charset=utf-8">       
  4. <title>test</title>  
  5. <styletype="text/css">   
  6. #ellipsis{  
  7.     width: 100px;  
  8.     overflow: hidden;  
  9.     white-space: nowrap;  
  10.     text-overflow: ellipsis;  
  11. }  
  12. </style>  
  13. </head>  
  14. <body>  
  15.     < div id = "ellipsis" > Today is your birthday, my country! ! ! </ div >   
  16.     <script>  
  17.         var clientWidth = document.getElementById("ellipsis").clientWidth;  
  18.         var scrollWidth = document.getElementById("ellipsis").scrollWidth;  
  19.         if(clientWidth<scrollWidth){  
  20.             alert("Omitted...");  
  21.         }  
  22.     </script>  
  23. </body>  
  24. </html>  

 

 

2. Knowledge point expansion offsetwidth clientwidth scrollwidth

scrollWidth: The width of the actual content of the object, excluding the width of the border, will become larger as the content in the object exceeds the visible area. 
clientWidth: The width of the visible area of ​​the object content, excluding scroll bars and other edges, will change with the display size of the object. 
offsetWidth: The actual width of the object as a whole, including the scroll bar and other edges, will change with the display size of the object.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327091812&siteId=291194637