私が取り組んでいる新しい Web サイトで奇妙な動作に気付きました。基本的に、Jqueryを使用して5秒ごとに他の画像にフェードインする背景として大きなバナー画像を持つランディングページがあります。コンピューターでは、フェード シーケンスは見事に機能しますが、モバイル デバイス (iPhone、iPad など) で表示すると画像が表示されません。私は当初、表示デバイスの画面サイズに関係があると思っていました (iPhone で画像が表示されない原因となっていました)。しかし、この問題は iPad でも発生するようです。画面の解像度が実際に問題なのかどうかはわかりません。
私が使用しているコードは、オンライン チュートリアルを少し変更したものです。基本的に、htmlコードは次のとおりです。
<div id="slideshow">
<img class="active" src="image1.jpg" alt="Slideshow Image 1" />
<img src="image2.jpg" alt="Slideshow Image 2" />
<img src="image3.jpg" alt="Slideshow Image 3" />
<img src="image4.jpg" alt="Slideshow Image 4" />
<img src="image5.jpg" alt="Slideshow Image 5" />
</div>
Jquery コードは次のようになります。
<script type="text/javascript">
function slideSwitch() {
var $active = $('#slideshow IMG.active');
if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
// use this to pull the images in the order they appear in the markup
var $next = $active.next().length ? $active.next()
: $('#slideshow IMG:first');
// uncomment the 3 lines below to pull the images in random order
// var $sibs = $active.siblings();
// var rndNum = Math.floor(Math.random() * $sibs.length );
// var $next = $( $sibs[ rndNum ] );
$active.addClass('last-active');
$next.css({opacity: 0.0})
.addClass('active')
.animate({opacity: 1.0}, 1000, function() {
$active.removeClass('active last-active');
});
}
$(function() {
setInterval( "slideSwitch()", 5000 );
});
</script>
少しの CSS コードもありますが、これが問題の原因であるかどうかは完全にはわかりません。それにもかかわらず:
#slideshow_content {
top: 50%;
position: fixed;
}
#slideshow {
position: absolute;
z-index: -1;
}
#slideshow IMG {
position: absolute;
top: 0;
left: 0;
z-index: 8;
opacity: 0.0;
}
#slideshow IMG.active {
z-index: 10;
opacity: 1.0;
}
#slideshow IMG.last-active {
z-index: 9;
}
#slideshow img {
max-width: 100%;
height: auto;
width: auto;
position: fixed;
top: 50%;
left: 0;
}
また、この問題が発生している私が取り組んでいる Web サイトへのリンクは、www.liftarchitects.comにあります。