Wrap Text inside fixed Div with css or javascript?

后端 未结 2 1078
情歌与酒
情歌与酒 2020-12-11 08:17

I have tinymce editor(textarea) and one div. Whenever I type inside the text editor, it shows at the preview div which is (200px) in real time which is looks alike stackover

相关标签:
2条回答
  • 2020-12-11 08:56

    I may be misunderstanding your issue, but it seems like all you need is a bit of CSS, specifically a max-width (for all the non-idiotic browsers) and a width with a wacky IE expression (for IE).

    For instance

    max-width:200px;
    _width:expression(document.body.clientWidth > 200? "200px": "auto" );
    

    When you combine that with the CSS you already have, it seems like it should work.

    0 讨论(0)
  • 2020-12-11 09:11
    function GetWrapedText(text, maxlength) {    
        var resultText = [""];
        var len = text.length;    
        if (maxlength >= len) {
            return text;
        }
        else {
            var totalStrCount = parseInt(len / maxlength);
            if (len % maxlength != 0) {
                totalStrCount++
            }
    
            for (var i = 0; i < totalStrCount; i++) {
                if (i == totalStrCount - 1) {
                    resultText.push(text);
                }
                else {
                    var strPiece = text.substring(0, maxlength - 1);
                    resultText.push(strPiece);
                    resultText.push("<br>");
                    text = text.substring(maxlength - 1, text.length);
                }
            }
        }
        return resultText.join("");
    }
    
    0 讨论(0)
提交回复
热议问题