数か月前に、非常にうまく機能する簡単な画像遷移スクリプトを作成しました。単に画像を交換するのではなく、スクリプトは最初に含まれる div の背景を最初の画像に設定します。このようにして、最初の画像が非表示になったときに、2 番目の画像がフェード インする間、ちらつきはありません。AdairHomes.comで遷移を表示できます。これは大きな画像の回転です。
HTML ラッパー
<div id="galleryContent" style="background:url(images/simple-banner-image-bath.jpg) top left;">
<img id="bannerImage" src="<!--Place the first image source here-->" alt="<!--Place your first ALT tag here-->" width="960" height="562" />
</div>
jQuery
<script type="text/javascript">
var banners = new Array();
// Array of images which you want to cycle
banners = [{"Source":"images/simple-banner-image-construction2.jpg","Alt":"Construction - Framing"},
{"Source":"images/simple-banner-image-bath.jpg","Alt":"Signature Custom Bathroom"},
{"Source":"images/simple-banner-image-2659.jpg","Alt":"Model Signature 2659"},
{"Source":"images/simple-banner-image-kitchen.jpg","Alt":"Signature Custom Kitchen"},
{"Source":"images/simple-banner-image-2432.jpg","Alt":"Model Signature 2432"},
{"Source":"images/simple-banner-image-1405.jpg","Alt":"Model Signature 1405"},
{"Source":"images/simple-banner-image-2830.jpg","Alt":"Model Signature 2830"}];
var count = banners.length - 1; // subtracting 1 accounts for the array starting at [0]
var counting = 0;
going = setInterval(function(){
$("#bannerImage").fadeOut(200,function(){
$(this).attr({'src':banners[counting]['Source'],'alt':banners[counting]['Alt']}).fadeIn(200);
});
// Select Next Picture
if(counting != count){counting++;}else{counting = 0;}
// Set new background image
$("#galleryContent").css({'background':'url('+banners[counting]['Source']+') top left'});
},6000);
var loadCount = 1;
// Preload images after the first image is displayed
slowLoad = setInterval(function(){
if(loadCount < banners.length){
$("body").append('<img src="'+banners[loadCount]['Source']+'" style="display:none;" />');
loadCount++;
}else{
clearInterval(slowLoad);
}
},500);
</script>
配列内で回転させているすべての画像を保持することを選択したことに気付くでしょう。これは、含まれているすべてのイメージを PHP で管理しているためです。
このコードでは、基本的には#galleryContent
div をスタイルして希望どおりに表示し、すべての画像を alt タグとともにバナー配列に追加するだけで済みます。また、最初に表示したいヘッダーを に配置する必要があります#bannerImage
。
さらにコードや支援が必要な場合はお知らせください。上記のリンクから、かなり良い感じを得ることができると思います。