今回は【jQuery】複数画像の切り替え、Image Rotatorの使い方!!
の解説になります!
こんな方に読んでほしい
- jQueryを学び始めた方へ
- プラグインのImage Rotatorを使って「複数画像の切り替え」をしたい方向け
- 今回はImage Rotatorについて解説しております。
今回は、「複数画像の切り替え(クロスフェード)」についての解説になります。
「Image Rotator」になりますが、今でも簡単で使いやすいプラグインになっております。
イメージ図は上記のようになります。
複数の画像が「フワッと(クロスフェード)」切り替わるイメージになります。
Image Rotatorについて
Image Rotatorとは、「複数画像の切り替え(クロスフェード)」のことを示します。
jQueryが苦手な方でも問題ありません。
まずは下記のサイトから「Image Rotator」をダウンロードしましょう。
必要なファイルについて
ダウンロード後に必要なファイルについて解説していきます。
まずは、ファイル名の「imageRotator-master」をご確認ください。
- ●jsファイル
- 1「imageRotator-master」 > 「imageRotator.js」の1点を使用します。
<!--js-->
<script src="js/imageRotator-master.js" type="text/javascript"></script>
また、「imageRotator-master.js」を使用する際には、imageRotatorを使用する宣言をしなければなりません。
以下のコードを合わせて指定しましょう。
<!--js-->
<script src="js/imageRotator-master.js" type="text/javascript"></script>
<script>
$(document).ready(function () {
var $imageDiv = $("#imageRotator");
var $imageRotator = $imageDiv.imageRotator({
imageTime: 3000,
fadeTime: 2000
});
$imageRotator.start();
});
</script>
「imageRotator-master.js」と繋げて記述するのが良いでしょう。
また、ファイルの階層は、ご自身のフォルダに合わせてください。
次に、jquery本体のプラグイン設置します。
今回は2つ目のパターンを採用して解説します。
● 1つ目は、ファイルをダウンロードして使用するパターン、
● 2つ目は、ファイルをダウンロードせずに、「URL」から読み込むパターンになります。
どちらでも問題ありません。
<!--js-->
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="js/imageRotator-master.js" type="text/javascript"></script>
<script>
$(document).ready(function () {
var $imageDiv = $("#imageRotator");
var $imageRotator = $imageDiv.imageRotator({
imageTime: 3000,
fadeTime: 2000
});
$imageRotator.start();
});
</script>
必ず、jquery本体のプラグイン上、imageRotator-masterを下に設置しましょう。
jqueryをダウンロードしたい方は、こちらのリンクから。
記述場所について
基本的にはbody
内に指定するようにしましょう。
基本構造の書き方は以下のようになります。
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title> 【jQuery】複数画像の切り替え...</title>
</head>
<body>
コンテンツが入ります。
<!--js-->
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="js/imageRotator-master.js" type="text/javascript"></script>
<script>
$(document).ready(function () {
var $imageDiv = $("#imageRotator");
var $imageRotator = $imageDiv.imageRotator({
imageTime: 3000,
fadeTime: 2000
});
$imageRotator.start();
});
</script>
</body>
</html>
「複数画像の切り替え」の設定について
次に、「複数画像の切り替え」の設定について解説します。
「複数画像の切り替え」の設定について
デモサイトはコチラから。
基本構造の書き方は以下のようになります。
「複数画像の切り替え」

<div id="imageRotator">
<img src="sample01.jpg" alt="">
<img src="sample02.jpg" alt="">
<img src="sample03.jpg" alt="">
</div><!--imageRotatorr-->
/*--CSS基本は変更 可 下記はデフォルトになります。--*/
/*--画像サイズは変更してください--*/
div#imageRotator {
height: 410px;
width: 740px;
}
div#imageRotator img {
margin: auto;
max-width: 100%;
max-height: 100%;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
$(document).ready(function () {
var $imageDiv = $("#imageRotator");
var $imageRotator = $imageDiv.imageRotator({
imageTime: 3000,
fadeTime: 2000
});
$imageRotator.start();
});
今回は、全体をid="imageRotator"
で囲み、
JavaScriptのvar $imageDiv = $("#imageRotator")
と同じ値にしております。
オプションについて
上記のオプションについて解説します。
まとめ
今回はこれで以上です。
スポンサーリンク

SHU
1991年生まれ九州の宮崎県育ち高校卒業後、愛知県で自動車関係のお仕事に5年間勤め、WEB業界に転職致しました。
趣味:サッカー観戦、ゲーム、映画、漫画基本インドアです!笑
つくる、しあわせをテーマとして主にWEBに関する様々な情報を発信しています。
最新記事
関連記事