画像をオーバーレイ表示 (jQuery と ColorBox を使用)
オーバーレイ表示では、例えば、下の画面のように、あるリンクをクリックすると、

画像などを、ブラウザ画面の前面に重ねあわせて表示するというようなことができる。 ColorBox を用いたオーバーレイ表示では、外部のHTMLやFlashなどの表示もできる。
ポップアップウインドウと違って、ブラウザの画面の任意の場所(オーバーレイ表示部分でなくてよい)をクリックすると、オーバーレイ表示が消える。
準備
◆ ダウンロード
- http://www.jacklmoore.com/colorbox を開く
- 「Current Version」のところをクリック
colorbox.zip がダウンロードが始まる
◆ JavaScript に関する Web ブラウザの設定
- Internet Explorer
インターネットオプションの「セキュリティの設定」で, 「スクリプト」→「アクティブ スクリプトを有効にする」
- Firefox
メニューのツール→オプション→Web 機能の設定
画像をオーバーレイ表示 (jQuery と ColorBox を使用)
まず、先ほどダウンロードした colorbox.zip を解凍。すると、color-master ディレクトリができる。 color-master を置いたディレクトリの中に、次のような HTML ファイルを作る(本当は、HTML ファイルのディレクトリはどこでもいいですが、 「colorbox-master/example2/colorbox.css」 と 「colorbox-master/jquery.colorbox-min.js」 のところを調整してください。
画像(「https://www.kkaneko.jp/sample/fruits.jpg」のところ)は適切に設定してください.
<?xml version="1.0" encoding="Shift_JIS"?>
<!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; initial-scale=1.0; charset=Shift_JIS" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="MSThemeCompatible" CONTENT="yes" />
<title>
画像のオーバーレイ表示の例
</title>
<link rel="stylesheet" href="./colorbox-master/example2/colorbox.css" />
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/prototype/1/prototype.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="./colorbox-master/jquery.colorbox-min.js"></script>
<script type="text/javascript">
<!--
jQuery.noConflict();
jQuery(document).ready(function($) {
$(".colorbox-fade").colorbox({rel:'colorbox-fade', transition:"fade"});
});
// -->
</script>
</head>
<body>
<p><a class="colorbox-fade" href="https://www.kkaneko.jp/sample/fruits.jpg" title="Fig. 1. Fruits">Photo 1</a></p>
</body>
</html>