Add dots/ellipsis on div/span element overflow without using jquery

前端 未结 5 1009
萌比男神i
萌比男神i 2021-02-04 06:58

Need to implement functionality similar to what dotdotdot jQuery plugin does but cannot use javascript frameworks (like jquery or ext).

Is there an

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-04 07:12

    My solution to my problem can seem a little awkward, but it works for me:)

    I used a little of CSS:

    word-wrap: break-word;
    

    and Javascript:

    var spans = document.getElementsByTagName("span");
    for (var i in spans) {
        var span = spans[i];
        if (/*some condition to filter spans*/) { // just 
            if (navigator.appName == 'Microsoft Internet Explorer') {
                span.parentNode.style.display ='inline-block';
            }
            if (span.parentNode.clientHeight > 50 ) {
                span.innerHTML = span.innerHTML.substr(0, 26) + ' ...';
            }
        }
    }
    

提交回复
热议问题