How to visually separate the text in the HTML to Google Docs?

0 like 0 dislike
29 views
by | 29 views

1 Answer

0 like 0 dislike

This video explains your answer: https://www.youtube.com/watch?v=cfsOU9SSLMI
 

try splitting the text at different places and watch until scroll Height is just less than or equal to client Height. Something like:

var divs = document.querySelectorAll('div');
var div = divs[0]
// Get text from content of first div - this wouldn't be what real code used
var text = div.textContent;

// Guess the split point as a percentage of the hidden characters
var splitPoint = text.length * div.clientHeight / div.scrollHeight;

// Find first space after splitpoint
splitPoint = text.indexOf(' ', splitPoint);

// Used to make sure we don't get into an infinite loop. Not needed if this code is proven to work on all browsers.
var count = 0;

div.textContent = text.substr(0, splitPoint);

// Add words until we are bigger 
while ((div.clientHeight == div.scrollHeight) && (count++ < 1000)) {
  splitPoint = text.indexOf(' ', splitPoint + 1);
  div.textContent = text.substr(0,splitPoint);
}
by (380 points)

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
0 like 0 dislike
7 answers
asked Mar 26, 2019 by DevArt
0 like 0 dislike
1 answer
asked Jun 13, 2019 by Vo1k
0 like 0 dislike
4 answers
asked Mar 22, 2019 by Cord
110,608 questions
257,186 answers
0 comments
1,245 users