About text content overflow with dot dot (...) Ellipsis indicates

Source: Internet
Author: User
Tags truncated

General CSS Method--can implement Ie,safari,chrome,opera browser text overflow ellipsis indicates that this is a test text, mainly used to test whether the text overflow will be displayed with ellipses.
1 . Zxx_text_overflow_1 {width:27em; white-space:nowrap; text-overflow:ellipsis; -o-text-overflow:ellipsis; overflow:hidden;}
How jquery limits character count
1 HTML section: 2 <  class= "zxx_text_overflow_5"> you kill thousand knives, how to write so many words, I want to be waist truncated ah, oh! </ Div >
1 no CSS, only JS code:2$ (document). Ready (function(){3     //limit the number of characters4$ (". Zxx_text_overflow_5"). each (function(){5         varMaxwidth=23;6         if($( This). Text () .length>maxwidth) {7$( This). Text ($ ( This). Text (). SUBSTRING (0, MaxWidth));8$( This). HTML ($ ( This). HTML () + ' ... ');9         }Ten     }); One});
How jquery automatically determines if the width is exceeded
1 HTML section: 2 <  class= "Zxx_text_overflow_6"> you kill thousand knives, how to write so many words, I want to be waist truncated ah, kitty save me! </ Div >

1 CSS sections: 2 . zxx_text_overflow_6{width:400px ;}

1 js section:2 varwordlimit=function(){3$ (". Zxx_text_overflow_6"). each (function(){4         varCopythis = $ ( This. CloneNode (true) . Hide (). css ({5' Position ': ' absolute ',6' Width ': ' Auto ',7' Overflow ': ' Visible '8         }); 9$( This). After (copythis);Ten         if(Copythis.width () >$ ( This). Width ()) { One$( This). Text ($ ( This). Text (). SUBSTRING (0,$ ( This). HTML (). length-4)); A$( This). HTML ($ ( This). HTML () + ' ... '); - Copythis.remove (); - wordlimit (); the}Else{ -Copythis.remove ();//Clear Replication -             return; -         } +     }); - } +Wordlimit ();

The former directly limits the number of characters, the latter by the width of the judgement, remove the last character, loop, until the text content width is less than the width of the div limit.

About text content overflow with dot dot (...) Ellipsis indicates

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.