Blog Archives

Membuat Slide Show Sederhana (javascript)

Berikut adalah kode javascript untuk membuat slide show sederhana dalam web anda.

File: script.js

var ganti= 1;
var jumlahgambar= 4;
var kecepatanganti=2000;

var img1=new Image();
var img2=new Image();
var img3=new Image();
var img4=new Image();

img1.src=”./Image/image1.jpg”;
img2.src=”./Image/image2.jpg”;
img3.src=”./Image/image3.jpg”;
img4.src=”./Image/image4.jpg”;

function ganti_gambar(){
if (document.images)
{
document.images.gambar.src=eval(“img”+ganti+”.src”);
if (ganti<jumlahgambar)
ganti++;
else
ganti= 1;
}
setTimeout(“ganti_gambar()”,kecepatanganti);
}

File: index.html

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”&gt;
<html>
<head>
<title>Template_1</title>
<script language=”JavaScript” src=”JS/slider.js”></script>
</head>

<body onload=”ganti_gambar()”>
<img src=”Image/image1.jpg” name=”gambar”>
</body>
</html>

 

Source code: Hedy Simamora

Advertisements