// ********* 蝮�ュ牙牡繧贋サ倥¢繧ケ繧ッ繝ェ繝励ヨ *********** // 謾ケ騾�縺ェ縺ゥ縺ッ縺碑�逕ア縺ォ陦後▲縺ヲ邨先ァ九〒縺吶′縲√%縺ョ繧ケ繧ッ繝ェ繝励ヨ縺昴�繧ゅ�繧定イゥ螢イ縺吶k縺薙→繧堤ヲ√§縺セ縺吶� // web螻� 蜀�陸縲http://www.web-naito.net/ // ***************** 2013.9.8 ***************** (function( $ ){ $.fn.justify = function(options) { return this.each(function(){ var words = $(this).text(), origFontSize = $(this).css("font-size").replace("px", ""), wordsLength = $(this).text().length, lineText = "", fontRatio = 0; if(wordsLength == 1) { $(this).css("text-align", "center"); return; } // 迴セ蝨ィ縺ョ譁�ォ�縺ョ蟷�r貂ャ繧� function grabPixelLineSize(text) { var dummy = '<div id="dummy" style="margin:0; padding:0; display: inline-block; font-size:' + origFontSize + ';">' + text + '</div>'; $("body").append(dummy); var emW = $("#dummy").width(); $("#dummy").remove(); return emW; }; var wordsWidth = grabPixelLineSize(words); // 譁�ュ怜�縺ョ蟷�r蜿門セ励☆繧� // 隕ェ隕∫エ�縺ョ遖∝援蜃ヲ逅�r辟。蜉ケ縺ォ縺吶k $(this).css("word-break", "keep-all"); var parentWidth = $(this).width(); // 隕ェ隕∫エ�縺ョ蟷�r蜿門セ励☆繧� var fontRatio = ( parentWidth - wordsWidth ) / (wordsLength - 1) /*- origFontSize.replace("px", "")*/; lineText += '<span style="letter-spacing: ' + fontRatio + 'px !important">' + words.slice(0, wordsLength-1) + '</span>' + words.slice(wordsLength-1); $(this).html(lineText); }); }; })(jQuery);