Text overflow implementation of the overflow part and then put in a newly generated div specific code _javascript tips

Source: Internet
Author: User
See someone in the group asking a question, say text overflow, how to implement overflow text into a newly generated div,

Think of the principle, is to determine whether to put down in the Div, if not, in the place should be disconnected, to the new Div, the code is as follows:
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html;charset=gb2312"/>
<title> text automatic insertion of different Div-jason yu</title>
<style type= "Text/css" >
*{margin:0;padding:0;}
Body{line-height:24px;font-family:simsun;font-size:12px;color: #000;}
#box1 {height:96px;}
. box{width:200px;overflow:hidden;margin-top:10px;border:1px solid #000;}
</style>
<body>
<div id= "box1" class= "box" ></div>
<script type= "Text/javascript" >
var str = "Here is a phrase, this short words can be very casual, oh, as long as a certain number, will automatically pagination, you believe it?" Do not believe also have to believe Ah, this is true, even if the long text, I copied a paragraph, the following passage is copied over, I am ready to replicate Oh, ready to do it? Here is a passage, this short words can be very casual, oh, as long as a certain number, will automatically page, you believe it or not? Do not believe also have to believe Ah, this is true, even if the long text, I copied a paragraph, the following passage is copied over, I am ready to replicate Oh, ready to do it? ";
var oBox1 = document.getElementById ("Box1");
function Fntextover (N1) {
var newBox2 = document.createelement ("div");
Document.body.appendChild (NEWBOX2);
Newbox2.classname = "box";
for (var i=n1; i<=str.length; i++) {
newbox2.innerhtml = str.substring (n1,i);
if (newbox2.offsetheight<=98) {
if (i==str.length) {
NewBox2.style.height = "96px";
}
}else{
newbox2.innerhtml = str.substring (n1,i-1);
NewBox2.style.height = "96px";
Arguments.callee (i-1);
Break
}
}
}

function Fnshowtext () {
var newbox = document.createelement ("div");
Document.body.appendChild (Newbox);
Newbox.classname = "box";
for (var i=1; i<=str.length; i++) {
newbox.innerhtml = str.substring (0,i);
if (newbox.offsetheight<=98) {
obox1.innerhtml = str.substring (0,i);
if (i==str.length) {
Document.body.removeChild (Newbox);
}
}else{
Document.body.removeChild (Newbox);
Fntextover (i-1);
Break
}
}
}
Fnshowtext ();
</script>
</body>

To add, the possible problems 1, the symbol in the next Div first appeared 2, letters such as "student" will be disconnected write, and other questions, need to be judged.

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.