実行結果
このdiv要素のクラスには「px」でfont-sizeプロパティが指定されています。
このdiv要素のクラスには「pt」でfont-sizeプロパティが指定されています。
このdiv要素のクラスには、「em」でfont-sizeプロパティが指定されています。
このdiv要素のクラスには、親要素に対するパーセンテージでfont-sizeプロパティが指定されています。
このdiv要素のクラスには、font-sizeプロパティが指定されていません。
設置サンプルのソース
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="ja" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="imagetoolbar" content="no" />
<title>Text Resizing With jQuery | 設置サンプル</title>
<link rel="stylesheet" type="text/css" href="/content/lib/global.css" />
<!-- JS -->
<script type="text/javascript" src="/content/lib/jquery/jquery-1.2.1.min.js"></script>
<script type="text/javascript" src="/content/lib/jquery/jquery.flydom-3.1.1.js"></script>
<script type="text/javascript">
$(function() {
// フォントサイズをリセット
var originalFontSize = $('html').css('font-size');
$(".resetFont").click(function(){
$('html').css('font-size', originalFontSize);
});
// フォントサイズを大きく
$(".increaseFont").click(function(){
var currentFontSize = $('html').css('font-size');
var currentFontSizeNum = parseFloat(currentFontSize, 10);
var newFontSize = currentFontSizeNum*1.2;
$('html').css('font-size', newFontSize);
return false;
});
// フォントサイズを小さく
$(".decreaseFont").click(function(){
var currentFontSize = $('html').css('font-size');
var currentFontSizeNum = parseFloat(currentFontSize, 10);
var newFontSize = currentFontSizeNum*0.8;
$('html').css('font-size', newFontSize);
return false;
});
});
</script>
<!-- CSS -->
<style type="text/css">
* {
font-size:100%;
}
body {
font-size:100%;
}
.pixels {
font-size:16px;
line-height:30px;
margin-bottom:20px;
padding:20px;
background-color:#222;
color:#fff;
}
.point {
font-size:12pt;
line-height:30px;
margin-bottom:20px;
padding:20px;
color:#fff;
background-color:#222;
}
.em {
font-size:1em;
margin-bottom:20px;
padding:20px;
color:#fff;
background-color:#222;
}
.percentage {
font-size:100%;
margin-bottom:20px;
padding:20px;
color:#fff;
background-color:#222;
}
.undefined {
margin-bottom:20px;
padding:20px;
color:#fff;
background-color:#222;
}
#changeFont {
position:absolute;
top:10px;
right:10px;
background-color:#333;
padding:5px;
}
.increaseFont,
.decreaseFont,
.resetFont {
color:#ccc;
font-size:14px;
float:left;
margin:10px;
}
</style>
<link rel="stylesheet" type="text/css" href="/common/css/example.css"></head>
<body id='example3' class='example'><div class="ads" style="margin:32px auto;text-align:center;"></div><h1 class='h'><a href='/'>PHP & JavaScript Room</a> :: 設置サンプル</h1>
<h3 class='h'>実行結果</h3>
<div id="wrap">
<h1><a href='http://www.shopdev.co.uk/blog/text-resizing-with-jquery/'>Text Resizing With jQuery</a> | 設置サンプル</h1>
<!-- CODE -->
<div class="pixels">このdiv要素のクラスには「px」でfont-sizeプロパティが指定されています。</div>
<div class="point">このdiv要素のクラスには「pt」でfont-sizeプロパティが指定されています。</div>
<div class="em">このdiv要素のクラスには、「em」でfont-sizeプロパティが指定されています。</div>
<div class="percentage">
このdiv要素のクラスには、親要素に対するパーセンテージでfont-sizeプロパティが指定されています。
</div>
<div class="undefined">
このdiv要素のクラスには、font-sizeプロパティが指定されていません。
</div>
<div id="changeFont">
<a href="#" class="increaseFont">大きく</a>
<a href="#" class="decreaseFont">小さく</a>
<a href="#" class="resetFont">リセット</a>
</div><!-- #changeFont -->
<!-- CODE / -->
</div>
</body>
</html>