IE系には、独自CSS word-break: break-all を適用し、それ以外のブラウザにはテキストの1文字ごとに任意改行文字(8203)をはさむプラグイン
jQuery(function($){
$.wb = {
version: 0.2
,sep: String.fromCharCode(8203)
,remake: function(elm){
var h = elm.contents();
elm.html('');
$(h).each(function(){
if(this.nodeType == 3){
elm.append($.trim(this.textContent.split('').join($.wb.sep)));
}else if(this.textContent == ''){
elm.append(this);
}else{
elm.append($.wb.remake($(this)));
}
});
return elm;
}
}
$.fn.wb = function(){
if(/msie/i.test(navigator.userAgent)){
$(this).css('word-break', 'break-all');
}else{
$.wb.sep = (/firefox\/2/i.test(navigator.userAgent)) ? '<wbr />' : String.fromCharCode(8203);
$(this).each(function(){ $.wb.remake($(this));});
}
return $(this);
}
});
jQuery(function($){
$('.word-break').wb();
});
| ddddddddddyyyyyyyyaaaaaaaaaaabbbbbbeeeeebbbbbbbbbbbbbbbbbcccccccccccccccccchhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh | あああああああああああああああああああああああああああああああああああああ |
| ddddddddddyyyyyyyyaaaaaaaaaaabbbbbbeeeeebbbbbbbbbbbbbbbbbcccccccccccccccccchhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh | あああああああああああああああああああああああああああああああああああああ |
copyright © 2008 bushimichi