我做了一个快速的功能,应该做你想要的。我评论了它,所以你知道发生了什么。
$(".box h1").each(function() {
  // Check if one line
  if($(this).height() <= parseInt($(this).css('line-height'))){
    // Check if width is greater than %50 of parent
    if($(this).width() >= $(this).parent().width()/2){
      // Adjust width to put it on two lines
      $(this).width($(this).parent().width()/2)
    }
  }
});
编辑:
要使第一行比第二行短,您必须做一些更复杂的事情。我从这个答案中使用了 cut 。这应该非常接近您想要的。
$(".box h1").each(function() {
  // Check if one line
  if($(this).height() <= parseInt($(this).css('line-height'))){
    // Check if width is greater than %50 of parent
    if($(this).width() >= $(this).parent().width()/2){
      // First find approximately where you want it
      place = Math.round($(this).val().length/2);         // Might need a parseFloat
      // Find nearest end of word in correct direction
      original = $(this);
      first = original.text(cut(place));
      end = first.val().length
      start = $(this).val().length - end
      second = $(this).substr(start,end)
      // Place a break tag in the middle to put it on two lines
      $(this).html(first + <br> + second)
    }
  }
});
这里剪了
function cut(n) {
    return function textCutter(i, text) {
        var short = text.substr(0, n);
        if (/^\S/.test(text.substr(n)))
            return short.replace(/\s+\S*$/, "");
        return short;
    };
}
此代码使用 a<br>分隔两行(第二行更长)
编辑2:
<br>如果没有添加新行的方法或其他方式,就不可能有不同的行长。如果您更喜欢它,我可以更改它,使其使用多个<h1>标签,我认为这会自动将每个添加标签踢到新行