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.