私がここで達成しようとしているのは、カルーセルの外側にある別のdivにイメージの中心にイメージがあるカルーセルです。中心に置かれた。私は「滑らかな」カルーセルを使用しており、カルーセルは正常に動作しています。 switch文は、デフォルトの場合にまっすぐに進みます。カルーセルのイメージキャプションを変更するJavaScript switchステートメント
JSが
(function ($) {
'use strict';
$(document).ready(function() {
var $idOne = document.getElementById('1'),
$idTwo = document.getElementById('2'),
$idThree = document.getElementById('3'),
$idFour = document.getElementById('4'),
$idFive = document.getElementById('5'),
$idSix = document.getElementById('6'),
$idSeven = document.getElementById('7'),
$idEight = document.getElementById('8'),
$idNine = document.getElementById('9'),
idArray = [
$idOne, $idTwo, $idThree, $idFour, $idFive, $idSix, $idSeven, $idEight, $idNine
];
switch (idArray) {
case $idOne:
$('#imageCaptions').html("this is image one's caption");
break;
case $idTwo:
$('#imageCaptions').html("this is image two's caption");
break;
case $idThree:
$('#imageCaptions').html("this is image three's caption");
break;
case $idFour:
$('#imageCaptions').html("this is image four's caption");
break;
case $idFive:
$('#imageCaptions').html("this is image five's caption");
break;
case $idSix:
$('#imageCaptions').html("this is image six's caption");
break;
case $idSeven:
$('#imageCaptions').html("this is image seven's caption");
break;
case $idEight:
$('#imageCaptions').html("this is image eight's caption");
break;
case $idNine:
$('#imageCaptions').html("this is image nine's caption");
break;
default:
$('#imageCaptions').html("sorry");
break;
}
});
})(jQuery);
htmlファイル
<div id="new">
<div class="center">
<div id="1">
<img src="http://placehold.it/350x300?text=1" class="img-responsive">
</div>
<div id="2">
<img src="http://placehold.it/350x300?text=2" class="img-responsive">
</div>
<div id="3">
<img src="http://placehold.it/350x300?text=3" class="img-responsive">
</div>
<div id="4">
<img src="http://placehold.it/350x300?text=4" class="img-responsive">
</div>
<div id="5">
<img src="http://placehold.it/350x300?text=5" class="img-responsive">
</div>
<div id="6">
<img src="http://placehold.it/350x300?text=6" class="img-responsive">
</div>
<div id="7">
<img src="http://placehold.it/350x300?text=7" class="img-responsive">
</div>
<div id="8">
<img src="http://placehold.it/350x300?text=8" class="img-responsive">
</div>
<div id="9">
<img src="http://placehold.it/350x300?text=9" class="img-responsive">
</div>
</div>
<div id="imageCaptions">
</div>
</div>
'スイッチ(idArray)は'意味をなさない。要素があり、キャプションを設定します。 –
私は変数の代入を引っかき、 'case'を次のようにしようとします:' case $( '#1'): 'また、' switch(idArray) 'は何をしていますか? –