- Home »
- Tutorial blog »
- Membuat Background Slide Show
Firliana Ayu Oktafia
On Kamis, 06 September 2012
Background Slide Show adalah gambar latar belakang yang bisa berganti-ganti secara otomatis setiap waktu yang telah ditentukan. Background ini disematkan di bagian body dengan posisi 100%.
Background Slide Show ini pertama-tama harus di load dengan JQuery yang biasanya dipasang di atas </head>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js' type='text/javascript'></script>
<script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js' type='text/javascript'></script>
Setelah itu dibagian CSS body, minimal harus ada seperti ini:
body {
background: black url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2KyZb9kaMk2i0HPZlkEcuWGJC1ooC_9el0uAbL6JP2I6Z-hVVRtDwYI7HoAD1V73Hb60W80obctYIavRYkR5mTbv4p24DTDZ3cV8eXqM3qJ_D8oDHTze7oZMU43KIY-F0u1RVrBaSqjY/s320/body-santa.jpg) repeat-x fixed top center;
-moz-background-size:100%;
-webkit-background-size:100%;
-o-background-size:100%;
background-size:100%;
}
Jika sudah terpasang juga, kita harus menambah JavaScript Backround Slide Show di bawah ini:
<script type='text/javascript'>
var ssBG={
gbr:[
"http://2.bp.blogspot.com/-jXDDlst7GMc/T1SDEQ72L6I/AAAAAAAAMKc/7C4dD51XSNY/s1600/Windows-8-HD-Wallpapers+%281%29.png",
"https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQXR9KYyzs7Vz0BvQQPC_UPCH17PR_jzd57Nj6cru0NwOpiIt4ZXMm_IlvNKAMugG5b2-rgwEk-9KiVJKf25TYQzr1ycyxfp8XKJLMFlD6t4xtpnzhgiqp8fWSAp6mI8KVlmfRGqQ/s1600/Windows+8+xTreme+Edition.jpg",
"https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8924XGdGhyphenhyphenWwr9mzWpjNnu7y8g9d0suFqrhrB9q9NVMKwGY1oieqS64IYPI2QCdOV97TG8Lfwl5oNaW4eUK_bJRY1SUb3bYR9LP64gQdvDMcmoRySS3VLcc1kvC48ZiNNPl9YjnHik5U/s1600/Windows_8_wallpapers_3.jpg",
"https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_ottC_gZctYKjTN8UySSKDcccRbyMWOgNaEmay6LyIJgCacTb5haptwK9LyVMfhLCeBqHa52WGXYfs7jmw8Hf_Nzd7q7W5cy6dqSROMmyspg3E8O5AmoubKxw9VWvWvSCZdBUOY0t_J8/s1600/windows8professional.jpg",
"http://www.smartearningmethods.com/wp-content/uploads/2012/03/Scenic-Windows-8-9.jpg",
"http://img225.imageshack.us/img225/4564/39003694.jpg",
"http://www.deviantart.com/download/243901871/windows_8_3d_by_faisalharoon-d417nvz.jpg",
"https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvGdIB3UVCm1jH-XT2Z5UftQ-jroZFZWTYG1hDRT28rYs_zvaN4s8Ttb-RMD2-d40rwI4mji2N8mSdoSWUYM1GviEqmd1SKvQ2f6XESNquaG1evIMeS7pRhX7mqyEbykVdTyT8KEeR28U/s1600/China_Country_4+%28wallpapersbay.blogspot.com%29.jpg",
"https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8a69k_2cxyXGKyJbefO-xupSI-TNgxfUc3VnFbLtx8D_LT6kuj_WhW_9JHZb42cNomYT088mn1QXPXaWiOXAErBVWtJmFQ6olk4hUyxD0lkVlo8Gs0lOZZxQz9YERX8OaMStKkdhvqeY/s1600/Rainbow_Wallpapers_(1)+%28wallpapersbay.blogspot.com%29.jpg",
"https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2uQiJMWaKW9CMIss2OhHDoeZo1tgavPethRW7Ljf9zRsxvGJpGcc83Lot7Y2eWvr2ndJM6jftaGbUSeygQ9I2ZMo7l-qqA5KGNypnwrEIlZu8ZVuXQ8e5t4RcTKn5hit_FWReAeFuE2A/s1600/Creative-Digital-Animal-Wallpapers-24+%28wallpapersbay.blogspot.com%29.jpg",
"1.bp.blogspot.com/_KjKudOQDFIw/TIBQjNvqJHI/AAAAAAAADRo/g_FBWqwMKAw/s1600/Thunder_Storm_Wallpapers_%2837%29+%28wallpapersbay.blogspot.com%29.jpg"
],
now:0,
SlideMyBG:function(list,style,speed,bgPos,bgSize,bgRep){
if(!ssBG.SlideMyBG.hasRun){ssBG.SlideMyBG.hasRun=true;
if(list==null||list==''){list=ssBG.gbr}else{if(typeof list!='object'){list=ssBG.gbr}}
if(style==null||style==''){style='random'}
if(speed==null||speed==''){speed=5000}
if(bgPos==null||bgPos==''){bgPos='top center'}
if(bgSize==null||bgSize==''){bgSize='100%'}
if(bgRep==null||bgRep==''){bgRep='repeat'}
ssBG.gaya=style;ssBG.jeda=speed;ssBG.gbr=list;ssBG.pos=bgPos;ssBG.size=bgSize;ssBG.rep=bgRep;
ssBG.opt={'background-attachment':'fixed','background-repeat':ssBG.rep,'-moz-background-size':ssBG.size,'background-size':ssBG.size};
}
if(ssBG.gaya=='random'){ssBG.gbr=ssBG.gbr.sort(function(){return 0.5-Math.random()})}
var img=new Image();var brp=ssBG.gbr.length;if(ssBG.now>=brp){ssBG.now=0}
var gbrSkrng=ssBG.gbr[ssBG.now];ssBG.now++;
if($('#bg-fader').length==0){$('body').prepend('<div id="bg-fader" style="opacity:0.0;top:0;left:0;width:100%;height:100%;background-color:'+$('body').css('background-color')+'"></div>');$('#bg-fader').css(ssBG.opt);$('body').css(ssBG.opt)}
$(img).load(function(){
$('#bg-fader').css({'background-image':'url('+gbrSkrng+')','background-position':ssBG.pos}).animate({opacity:1.0},'slow','linear',function(){
$('body').css({'background-image':'url('+gbrSkrng+')','background-position':ssBG.pos});
$(this).animate({opacity:0.0},'slow','linear');
setTimeout("ssBG.SlideMyBG()",ssBG.jeda);
});
}).attr('src',gbrSkrng).error(function(huh){ssBG.SlideMyBG()});
}
};
</script>
<script type='text/javascript'>$(window).load(function(){ssBG.SlideMyBG()})</script>