■画面上で文字列の幅を調べる jQueryを利用して対象の文字列が画面上で何ピクセルあるのか、というのを取得するサンプルです。画面上での文字の幅を取得することで、折り返しが発生しないようにフォントサイズに自動調整したり、ということが可能になります。 以下、サンプルコードです。 <!DOCTYPE html> <html lang="ja"> <head> <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.1.min.js"></script> <script> $(document).ready(function(){ string = 'ほげほげほげほげほげー'; // ここでstringに入っている文字列の幅のピクセル数を取得することができる。 widthPixel = strWidth(string); al
![JQueryを使って画面上の文字列の幅を取得するサンプル | 怪しい物を開発するブログ](https://cdn-ak-scissors.b.st-hatena.com/image/square/fbf4e4f6464728cdf554edcb549f5eba5f4ca576/height=288;version=1;width=512/https%3A%2F%2Fblog.supersonico.info%2Fwp-content%2Fuploads%2F2015%2F11%2Fame842_okuirikeiryu_TP_V-2.jpg)