Membuat Slideshow dengan Apple Styles

Membuat Slideshow dengan Apple Styles

Ketika kita berbicara tentang web design dan usability, maka kita tidak dapat melupakan sebuah perusahaan IT yaitu Apple. Produk-produk apple terkenal dengan design dan usability yang menawan. Ketika kita mengunjugi website apple kita akan melihat sebuah slide show yang terdiri atas dua bagian yaitu galery product dan thumbnailnya. Pada tutorial ini kita akan memadukan antara css dan jquery untuk membuat slideshow yang mirip seperti punyanya apple

1. Membuat Struktur HTML

Berikut ini adalah struktur Utama dari slideshow

<div id="main">
	<div id="gallery">
		<div id="slides">
			<div class="slide"><img src="img/sample_slides/macbook.jpg" width="920" height="400" /></div>
			<div class="slide"><img src="img/sample_slides/iphone.jpg" width="920" height="400" /></div>
			<div class="slide"><img src="img/sample_slides/imac.jpg" width="920" height="400" /></div>
		</div>
		<div id="menu">
			<ul>
				<li class="fbar">&nbsp;</li>
				<li class="menuItem"><a href=""><img src="img/sample_slides/thumb_macbook.png" /></a></li>
				<li class="menuItem"><a href=""><img src="img/sample_slides/thumb_iphone.png" /></a></li>
				<li class="menuItem"><a href=""><img src="img/sample_slides/thumb_imac.png" /></a></li>
			</ul>
		</div>
	</div>
</div>

Secara umum ada dua div utama yaitu Div dengan Id=”Menu” dan id=”slides”. Div menu berfungsi sebagai tempat thumbnail dari div Slides. Jadi jumlah image yang ada di slide harus sama dengan jumlah yang ada du thumbnail.

Untuk menambah/mengganti slide cukup dengan menambah atau mengganti image silde dan thumbnailnya. untuk thumbnail anda harus menngunakan tipe PNG.

2. Memberikan Style Css

Slideshow Apple

Selelah terbentuk strukturnya step selanjutnya adalah memberikan style pada struktur tersebut.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
body,h1,h2,h3,p,quote,small,form,input,ul,li,ol,label{
	/* Page reset */
	margin:0px;
	padding:0px;
}
 
body{
	/* Setting default text color, background and a font stack */
	color:#444444;
	font-size:13px;
	background: #f2f2f2;
	font-family:Arial, Helvetica, sans-serif;
}
 
/* Gallery styles */
 
#gallery{
	/* CSS3 Box Shadow */
	-moz-box-shadow:0 0 3px #AAAAAA;
	-webkit-box-shadow:0 0 3px #AAAAAA;
	box-shadow:0 0 3px #AAAAAA;
 
	/* CSS3 Rounded Corners */
 
	-moz-border-radius-bottomleft:4px;
	-webkit-border-bottom-left-radius:4px;
	border-bottom-left-radius:4px;
 
	-moz-border-radius-bottomright:4px;
	-webkit-border-bottom-right-radius:4px;
	border-bottom-right-radius:4px;
 
	border:1px solid white;
 
	background:url(img/panel.jpg) repeat-x bottom center #ffffff;
 
	/* The width of the gallery */
	width:920px;
	overflow:hidden;
}
 
#slides{
	/* This is the slide area */
	height:400px;
 
	/* jQuery changes the width later on to the sum of the widths of all the slides. */
	width:920px;
	overflow:hidden;
}
 
.slide{
	float:left;
}
 
#menu{
	/* This is the container for the thumbnails */
	height:45px;
}
 
ul{
	margin:0px;
	padding:0px;
}
 
li{
	/* Every thumbnail is a li element */
	width:60px;
	display:inline-block;
	list-style:none;
	height:45px;
	overflow:hidden;
}
 
li.inact:hover{
	/* The inactive state, highlighted on mouse over */
	background:url(img/pic_bg.png) repeat;
}
 
li.act,li.act:hover{
	/* The active state of the thumb */
	background:url(img/active_bg.png) no-repeat;
}
 
li.act a{
	cursor:default;
}
 
.fbar{
	/* The left-most vertical bar, next to the first thumbnail */
	width:2px;
	background:url(img/divider.png) no-repeat right;
}
 
li a{
	display:block;
	background:url(img/divider.png) no-repeat right;
	height:35px;
	padding-top:10px;
}
 
a img{
	border:none;
}

3. Menambahkan Script jQuery

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
$(document).ready(function(){
	var totWidth=0;
	var positions = new Array();
        //Lakukan luping di semua div image didalam div slide
	$('#slides .slide').each(function(i){
		positions[i]= totWidth;
		totWidth += $(this).width();
 
		if(!$(this).width())
		{
			alert("Please, fill in width & height for all your images!");
			return false;
		}
	});
 
	$('#slides').width(totWidth);
 
        //jika thumbnail di klik
	$('#menu ul li a').click(function(e){
 
		$('li.menuItem').removeClass('act').addClass('inact');
		$(this).parent().addClass('act');
 
		var pos = $(this).parent().prevAll('.menuItem').length;
		$('#slides').stop().animate({marginLeft:-positions[pos]+'px'},450);
 
		e.preventDefault();
	});
 
	$('#menu ul li.menuItem:first').addClass('act').siblings().addClass('inact');
});

Kode ini sangat simple, kita akan memanfaatkan fungsi animasi dari jquery untuk mempermudah proses slideshow.

Dimodifikasi dari http://tutorialzine.com/2009/11/beautiful-apple-gallery-slideshow/

Artikel yang berhubungan

About ibnoe
Hi, my name is Ibnu Daqiqil Id and I’m an indonesian Web Developer. I love creating simple, unique and easy-to-use web application and what most counts for me is to work with people who are passionate about what they do.

3 Responses to “Membuat Slideshow dengan Apple Styles”

  1. husen says:

    ak pke slide ini di web q.tp mash offline.
    dari semua configurasi tak bikin satu di file.php
    wktu di esekusi melaui
    “http://localhost/demo/gallery.php”
    dia bisa muncul
    tetapi wktu saya panggil agar di dalam web,dia tidak muncul!!
    tolong bantuananya

  2. ibnoe says:

    mungkin path imagenya salah mas.. coba di cek lagi

  3. bukhory212 says:

    tambah mantap neh belajar jquery nya..


Leave a Reply

Tags

,

Postingan Terbaru

Copyright © 2010 Tutorial PHP Jquery Codeigniter Ajax javascript