82mou
1/6/2017 - 8:30 AM

文字数に応じてで3点リーダーを設定するjs

文字数に応じてで3点リーダーを設定するjs

var stringCut = function(that, i) {
    var $setElm = $(that),
        cutFigure = i, // カットする文字数
        afterTxt = '…', // 文字カット後に表示するテキスト
        textLength = $setElm.text().length,
        textTrim = $setElm.text().substr(0, (cutFigure));
    if (cutFigure < textLength) {
        $setElm.html(textTrim + afterTxt).removeClass('vh');
    } else if (cutFigure >= textLength) {
        $setElm.removeClass('vh');
    }
};