各种浏览器 多行截断

/**
   * @description 超出字符截取
   * @param {*} cls class名称
   */
  function fixLine(cls) {
    console.time();
    $("." + cls).each(function () {
        var _this = $(this);
        var content = _this.attr('data-content')
        _this.text(content);
        var outHeight = _this.parent().height();
        for (var i = 0; i < content.length+1;i+=2) {
            _this.text(content.substr(0, i))
            if (outHeight < _this[0].scrollHeight - 5) {
                _this.css('overflow', 'hidden').text(content.substr(0, i - 6) + '...')
                break;
            }
        }
    });

css 设置高度 父级 

  

猜你喜欢

转载自www.cnblogs.com/nns4/p/10844386.html
今日推荐