jqueryの基本的な画像ギャラリーであるこのコードを書きました
$(document).ready(function() {
setInterval("rotateImages()",2000)
})
function rotateImages() {
var curPhoto = $("#photoshow div.current");
var nextPhoto = curPhoto.next();
if (nextPhoto.length == 0) {
nextPhoto = $("#photoshow div:first");
}
curPhoto.removeClass("current").addClass("previous");
nextPhoto.css({
opacity: 0.0
}).addClass("current").animate({
opacity: 1.0
}, 1000, function () {
curPhoto.removeClass("previous")
});
}
これは機能しますが、if ステートメントを {} でラップする場合は機能しません。2つの違いと、なぜうまくいかないのかを理解したかっただけです。