Jquery load content show content
Ik ben al een tijdje bezig met een bepaalde techniek, maar kom er niet uit hoe ik dit moet uitpakken.
Wat ik wil is het volgende.
Het gaat om een portfolio site voor een fotograaf. Wanneer je op een bepaald event klikt, krijg je een overzicht met thumbs met foto's van het desbetreffende event. Wat ik nu wil is, wanneer er op een willekeurige thumb wordt geklikt, er een div open slide en de thumbs naar ondere meeduwd als het waren.
Waarna er in die div een slider staat.
Zovel de image als de content moet automatisch veranderen.
De stappen samengevat:
Overzicht van thumbnails
Klik op een willekeurige projectbox a tag
Slide the contentbox naar beneden.
Navigatie via de slideshow, opacity laat zien welke foto het is.
Kan iemand mij hierin helpen?
Alvast enerom bedankt.
Casper
Toevoeging op 02/03/2012 21:59:05:
Om het wat beter te verduidelijken,
dit is het idee wat ik wil, alleen dat hij maar 1 keer open gaat, tenzij je op close klikt...
http://themes.nistic.com/william/
Verder is het belangrijk dat, wanneer je bijv op foto 2 klikt dat je dan niet standaard foto 1 krijgt maar daadwerkelijk ook foto 2.
En nog een voorbeeld: http://8020.com/
Om bij het begin te beginnen. Wat heb je wel al en wat is het eerste probleem waar je tegen aan loopt. Op zich is alles wat je wilt namelijk niet zo moeilijk met JQuery, alleen je zal het wel stap voor stap moeten doen.
Ik had zelf een beetje gekeken hoe de website van 8020 er uit zag qua code. Deze heb ik redelijk ver weten te verschonen wat voor mij nog van belang was.
De pagina bestond uit verschillende divs met de project naam als id. Wanneer je op bijv. Nederland klikt, krijg je de pagina nederland (display: none wordt dan overschreden) etc.
Die pagina bevat steeds een slider met de bijbehorende inhoud.
Zoals in de code te zien is een slider voor #better-place en #wb.
Deze wil ik nu eigenlijk samenvoegen tot 1 slider.
Wat ik nu nog wil bereiken is dat je met de links een bepaalde foto te zien krijgt,
als voorbeeld: je kiest thumb 2, je krijgt foto 2.
Wat dan nog de bedoeling is, is dat ik dan vanaf foto 2 verder kan slide met de nav van de slider naar foto 3 etc. of terug naar foto 1. En dat de title ook van die bepaalde foto geshowed wordt.
Hopelijk kunnen jullie mij helpen.
Hierbij de codes:
index.html
Code (php)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<!DOCTYPE html>
<html>
<head>
<title>80/20</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="data/project-images.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery-1.4.4.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.easySlider.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.imgload.js" type="text/javascript" charset="utf-8"></script>
<script src="js/master.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css">
h1,h2,h3,h4,h5,h6,p,blockquote,img { margin:0; padding:0; border:0; outline:0; font-weight:inherit; font-style:inherit; font-size:100%; font-family:inherit; vertical-align:baseline; }
:focus { outline:0; }
a:active { outline:none; }
ol,ul { list-style:none; }
/* ********************************************************************************* */
/* 1. Document Setup */
/* ********************************************************************************* */
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #333;
margin: auto;
background: #f4f4f4 url(../images/bg.jpg) center top fixed;
}
#work {
height: auto;
width: 920px;
margin: 20px auto;
}
#projectbox {
padding: 0;
margin: 0;
height: 300px;
width: 295px;
}
#projectbox li {
-moz-transition: all 0.2s ease-in-out 0s;
display: block;
float: left;
}
#projectbox a {
-moz-transition: all 0.2s ease-in-out 0s;
color: #3333;
display: block;
height: 233px;
float: left;
text-decoration: none;
text-transform: uppercase;
}
#work-container {
height: 0;
margin-top: -1px;
overflow: hidden;
position: relative;
width: 920px;
}
div.work-details {
border-bottom: 1px solid #CCCDCE;
border-top: 1px solid #CCCDCE;
display: none;
position: absolute;
top: 0;
width: 920px;
}
div.work-details section {
margin: 0 auto;
width: 920px;
}
div.work-details section:after {
clear: both;
content: ".";
display: block;
height: 0;
line-height: 0;
visibility: hidden;
}
.sliderbox {
height: 550px;
width: 920px;
margin: 0 auto 0 auto;
float: left;
position: relative;
background: #FFF;
}
.sliderbox ul, .sliderbox li {
line-height: 0;
list-style: none outside none;
margin: 0;
padding: 0;
}
.sliderbox li {
height: 500px;
width: 920px;
position: relative;
}
.sliderbox img {
position: absolute;
left: 0;
top: 0;
z-index: 0;
}
.sliderbox img.empty {
z-index: 100;
}
.sliderbox div {
background-color: #444751;
bottom: 0;
color: #A2A3A8;
height: 50px;
left: 0;
position: absolute;
width: 920px;
}
.sliderbox div span {
position: absolute;
}
.sliderbox div span.control-prev {
left: 15px;
top: 15px;
}
.sliderbox div span.control-next {
left: 56px;
top: 16px;
}
.sliderbox div span.control-counter {
right: 30px;
top: 26px;
}
.sliderbox div span a {
display: block;
height: 31px;
text-indent: -9999px;
width: 31px;
}
.sliderbox div span.control-prev, .sliderbox div span.control-prev a {
background: url("img/control-prev.png") no-repeat scroll 0 0 transparent;
height: 31px;
width: 31px;
}
.sliderbox div span.control-next, .sliderbox div span.control-next a {
background: url("img/control-next.png") no-repeat scroll 0 0 transparent;
height: 31px;
width: 31px;
}
.sliderbox div span a:hover {
background-position: 0 -31px;
}
.contentbox {
height: auto;
width: 920px;
margin: 17px 0 0 0;
float: left;
background: #FFF;
}
.titlebox {
height: 30px;
padding: 16px 10px 4px 10px;
font-size: 16px;
color: #FFF;
text-align: center;
background: #444750;
}
.navbox {
height: auto;
padding: 20px 20px 20px 20px;
font-size: 16px;
color: #FFF;
background: #444750;
}
.textbox {
height: auto;
padding: 20px 20px 20px 20px;
}
#textalign {
text-align: left;
padding: 16px 10px 4px 20px;
}
#close {
height: 40px;
width: 40px;
}
</style>
</head>
<body>
<section id="work">
<section id="work-container">
<div id="better-place" class="work-details">
<section>
<div class="sliderbox">
<ul>
<li><img src="img/evo.jpg" alt="" /></li>
</ul>
</div>
<div class="contentbox">
<div class="navbox">EVO.</div><!-- End .titlebox -->
<div class="textbox">
Scuderia Hanseat October 2011,
<br>
Nrburgring GP-strecke, Paddock
</div><!-- End .textbox -->
</div><!-- End .contentbox -->
</section>
</div> <!-- close #better-place -->
<div id="wb" class="work-details">
<section>
<div class="sliderbox">
<ul>
<li><img src="img/sls.jpg" alt="" /></li>
</ul>
</div>
<div class="contentbox">
<div class="navbox">SLS.</div><!-- End .titlebox -->
<div class="textbox">
RTS Trackdays, August 2011,
<br>
Nordschleife, T13
</div><!-- End .textbox -->
</div><!-- End .contentbox -->
</section>
</div> <!-- close #wb -->
</section> <!-- close #work-container -->
<br><br><br><br><br><br>
<ul id="projectbox">
<li id="projectbox-better-place"><a href="#better-place"><span class="project-name">EVO.</span></a>
</ul>
<ul id="projectbox">
<li id="projectbox-wb"><a href="#wb"><span class="project-name">SLS.</span></a></li>
<br>
</ul>
</section> <!-- close #work -->
</body>
</html>
<html>
<head>
<title>80/20</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="data/project-images.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery-1.4.4.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.easySlider.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.imgload.js" type="text/javascript" charset="utf-8"></script>
<script src="js/master.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css">
h1,h2,h3,h4,h5,h6,p,blockquote,img { margin:0; padding:0; border:0; outline:0; font-weight:inherit; font-style:inherit; font-size:100%; font-family:inherit; vertical-align:baseline; }
:focus { outline:0; }
a:active { outline:none; }
ol,ul { list-style:none; }
/* ********************************************************************************* */
/* 1. Document Setup */
/* ********************************************************************************* */
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #333;
margin: auto;
background: #f4f4f4 url(../images/bg.jpg) center top fixed;
}
#work {
height: auto;
width: 920px;
margin: 20px auto;
}
#projectbox {
padding: 0;
margin: 0;
height: 300px;
width: 295px;
}
#projectbox li {
-moz-transition: all 0.2s ease-in-out 0s;
display: block;
float: left;
}
#projectbox a {
-moz-transition: all 0.2s ease-in-out 0s;
color: #3333;
display: block;
height: 233px;
float: left;
text-decoration: none;
text-transform: uppercase;
}
#work-container {
height: 0;
margin-top: -1px;
overflow: hidden;
position: relative;
width: 920px;
}
div.work-details {
border-bottom: 1px solid #CCCDCE;
border-top: 1px solid #CCCDCE;
display: none;
position: absolute;
top: 0;
width: 920px;
}
div.work-details section {
margin: 0 auto;
width: 920px;
}
div.work-details section:after {
clear: both;
content: ".";
display: block;
height: 0;
line-height: 0;
visibility: hidden;
}
.sliderbox {
height: 550px;
width: 920px;
margin: 0 auto 0 auto;
float: left;
position: relative;
background: #FFF;
}
.sliderbox ul, .sliderbox li {
line-height: 0;
list-style: none outside none;
margin: 0;
padding: 0;
}
.sliderbox li {
height: 500px;
width: 920px;
position: relative;
}
.sliderbox img {
position: absolute;
left: 0;
top: 0;
z-index: 0;
}
.sliderbox img.empty {
z-index: 100;
}
.sliderbox div {
background-color: #444751;
bottom: 0;
color: #A2A3A8;
height: 50px;
left: 0;
position: absolute;
width: 920px;
}
.sliderbox div span {
position: absolute;
}
.sliderbox div span.control-prev {
left: 15px;
top: 15px;
}
.sliderbox div span.control-next {
left: 56px;
top: 16px;
}
.sliderbox div span.control-counter {
right: 30px;
top: 26px;
}
.sliderbox div span a {
display: block;
height: 31px;
text-indent: -9999px;
width: 31px;
}
.sliderbox div span.control-prev, .sliderbox div span.control-prev a {
background: url("img/control-prev.png") no-repeat scroll 0 0 transparent;
height: 31px;
width: 31px;
}
.sliderbox div span.control-next, .sliderbox div span.control-next a {
background: url("img/control-next.png") no-repeat scroll 0 0 transparent;
height: 31px;
width: 31px;
}
.sliderbox div span a:hover {
background-position: 0 -31px;
}
.contentbox {
height: auto;
width: 920px;
margin: 17px 0 0 0;
float: left;
background: #FFF;
}
.titlebox {
height: 30px;
padding: 16px 10px 4px 10px;
font-size: 16px;
color: #FFF;
text-align: center;
background: #444750;
}
.navbox {
height: auto;
padding: 20px 20px 20px 20px;
font-size: 16px;
color: #FFF;
background: #444750;
}
.textbox {
height: auto;
padding: 20px 20px 20px 20px;
}
#textalign {
text-align: left;
padding: 16px 10px 4px 20px;
}
#close {
height: 40px;
width: 40px;
}
</style>
</head>
<body>
<section id="work">
<section id="work-container">
<div id="better-place" class="work-details">
<section>
<div class="sliderbox">
<ul>
<li><img src="img/evo.jpg" alt="" /></li>
</ul>
</div>
<div class="contentbox">
<div class="navbox">EVO.</div><!-- End .titlebox -->
<div class="textbox">
Scuderia Hanseat October 2011,
<br>
Nrburgring GP-strecke, Paddock
</div><!-- End .textbox -->
</div><!-- End .contentbox -->
</section>
</div> <!-- close #better-place -->
<div id="wb" class="work-details">
<section>
<div class="sliderbox">
<ul>
<li><img src="img/sls.jpg" alt="" /></li>
</ul>
</div>
<div class="contentbox">
<div class="navbox">SLS.</div><!-- End .titlebox -->
<div class="textbox">
RTS Trackdays, August 2011,
<br>
Nordschleife, T13
</div><!-- End .textbox -->
</div><!-- End .contentbox -->
</section>
</div> <!-- close #wb -->
</section> <!-- close #work-container -->
<br><br><br><br><br><br>
<ul id="projectbox">
<li id="projectbox-better-place"><a href="#better-place"><span class="project-name">EVO.</span></a>
</ul>
<ul id="projectbox">
<li id="projectbox-wb"><a href="#wb"><span class="project-name">SLS.</span></a></li>
<br>
</ul>
</section> <!-- close #work -->
</body>
</html>
JQUERY EASYSLIDER
Code (php)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*
* Easy Slider 1.7 - jQuery plugin
* written by Alen Grakalic
* http://cssglobe.com/post/4004/easy-slider-15-the-easiest-jquery-plugin-for-sliding
*
* Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* Built for jQuery library
* http://jquery.com
*
*/
/*
* markup example for $("#slider").easySlider();
*
* <div id="slider">
* <ul>
* <li><img src="images/01.jpg" alt="" /></li>
* <li><img src="images/02.jpg" alt="" /></li>
* <li><img src="images/03.jpg" alt="" /></li>
* <li><img src="images/04.jpg" alt="" /></li>
* <li><img src="images/05.jpg" alt="" /></li>
* </ul>
* </div>
*
*/
(function($) {
$.fn.easySlider = function(options){
// default configuration properties
var defaults = {
prevId: "prev",
prevText: "Previous",
nextId: "next",
nextText: "Next",
controlsShow: true,
controlsFade: true,
speed: 800,
auto: false,
pause: 2000,
continuous: true,
project: "project"
};
var options = $.extend(defaults, options);
this.each(function() {
/* --------------------------------------------------------------------------
=setup
--------------------------------------------------------------------------- */
var obj = $(this);
var s = $("li", obj).length;
var w = $("li", obj).width();
w = 920; // hardcoded for legacy support
var h = $("li", obj).height();
h = 500; // hardcoded for legacy support
var clickable = true;
obj.css("overflow","hidden");
var ts = s-1;
var t = 0;
// setup ids for injected elements based on project name
var counterId = "counter-"+options.project;
var prevId = "prev-"+options.project;
var nextId = "next-"+options.project;
// display values for x/y readout
var countCurrent = 1;
var countTotal = s;
// setup row of images
$("ul", obj).css("width",s*w);
if(options.continuous){
$("ul", obj).prepend($("ul li:last-child", obj).clone().css("margin-left","-"+ w +"px"));
$("ul", obj).append($("ul li:nth-child(2)", obj).clone());
$("ul", obj).css("width",(s+1)*w);
};
$("li", obj).css("float","left");
// setup controls
if(options.controlsShow){
var html;
html += "<div>";
html += "<span id=\""+prevId+"\" class=\"control-prev\"><a href=\"javascript:void(0);\">"+ options.prevText +"</a></span>";
html += "<span id=\""+counterId+"\" class=\"control-counter\"></span>";
html += "<span id=\""+nextId+"\" class=\"control-next\"><a href=\"javascript:void(0);\">"+ options.nextText +"</a></span>";
html += "</div>";
$(obj).append(html);
};
// add function to anchor image wrapper
$("img", obj).wrap("<a href=\"javascript:void(0);\"></a>");
$("li a", obj).click(function(){
animate("next",true);
});
// add function to next/prev buttons
$("a","#"+nextId).click(function(){
animate("next",true);
});
$("a","#"+prevId).click(function(){
animate("prev",true);
});
// add actual value for the counter
updateCountDisplay();
/* --------------------------------------------------------------------------
=functions
--------------------------------------------------------------------------- */
function updateCountDisplay(){
$("#"+counterId).empty();
$("#"+counterId).append(countCurrent+"/"+countTotal);
}
function adjust(){
if(t>ts) t=0;
if(t<0) t=ts;
$("ul",obj).css("margin-left",(t*w*-1));
clickable = true;
};
function animate(dir,clicked){
if (clickable){
clickable = false;
var ot = t;
switch(dir){
case "next":
countCurrent = (countCurrent>=countTotal) ? 1 : countCurrent+1;
t = (ot>=ts) ? (options.continuous ? t+1 : ts) : t+1;
break;
case "prev":
countCurrent = (countCurrent<=1) ? countTotal : countCurrent-1;
t = (t<=0) ? (options.continuous ? t-1 : 0) : t-1;
break;
default:
t = dir;
break;
};
// update counter
updateCountDisplay();
var diff = Math.abs(ot-t);
var speed = diff*options.speed;
p = (t*w*-1);
$("ul",obj).animate(
{ marginLeft: p },
{ queue:false, duration:speed, complete:adjust }
);
if(!options.continuous && options.controlsFade){
if(t==ts){
$("a","#"+nextId).hide();
} else {
$("a","#"+nextId).show();
};
if(t==0){
$("a","#"+prevId).hide();
} else {
$("a","#"+prevId).show();
};
};
if(clicked) clearTimeout(timeout);
if(options.auto && dir=="next" && !clicked){;
timeout = setTimeout(function(){
animate("next",false);
},diff*options.speed+options.pause);
};
};
};
/* --------------------------------------------------------------------------
=init
--------------------------------------------------------------------------- */
var timeout;
if(options.auto){;
timeout = setTimeout(function(){
animate("next",false);
},options.pause);
};
if(!options.continuous && options.controlsFade){
$("a","#"+prevId).hide();
};
});
};
})(jQuery);
* Easy Slider 1.7 - jQuery plugin
* written by Alen Grakalic
* http://cssglobe.com/post/4004/easy-slider-15-the-easiest-jquery-plugin-for-sliding
*
* Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* Built for jQuery library
* http://jquery.com
*
*/
/*
* markup example for $("#slider").easySlider();
*
* <div id="slider">
* <ul>
* <li><img src="images/01.jpg" alt="" /></li>
* <li><img src="images/02.jpg" alt="" /></li>
* <li><img src="images/03.jpg" alt="" /></li>
* <li><img src="images/04.jpg" alt="" /></li>
* <li><img src="images/05.jpg" alt="" /></li>
* </ul>
* </div>
*
*/
(function($) {
$.fn.easySlider = function(options){
// default configuration properties
var defaults = {
prevId: "prev",
prevText: "Previous",
nextId: "next",
nextText: "Next",
controlsShow: true,
controlsFade: true,
speed: 800,
auto: false,
pause: 2000,
continuous: true,
project: "project"
};
var options = $.extend(defaults, options);
this.each(function() {
/* --------------------------------------------------------------------------
=setup
--------------------------------------------------------------------------- */
var obj = $(this);
var s = $("li", obj).length;
var w = $("li", obj).width();
w = 920; // hardcoded for legacy support
var h = $("li", obj).height();
h = 500; // hardcoded for legacy support
var clickable = true;
obj.css("overflow","hidden");
var ts = s-1;
var t = 0;
// setup ids for injected elements based on project name
var counterId = "counter-"+options.project;
var prevId = "prev-"+options.project;
var nextId = "next-"+options.project;
// display values for x/y readout
var countCurrent = 1;
var countTotal = s;
// setup row of images
$("ul", obj).css("width",s*w);
if(options.continuous){
$("ul", obj).prepend($("ul li:last-child", obj).clone().css("margin-left","-"+ w +"px"));
$("ul", obj).append($("ul li:nth-child(2)", obj).clone());
$("ul", obj).css("width",(s+1)*w);
};
$("li", obj).css("float","left");
// setup controls
if(options.controlsShow){
var html;
html += "<div>";
html += "<span id=\""+prevId+"\" class=\"control-prev\"><a href=\"javascript:void(0);\">"+ options.prevText +"</a></span>";
html += "<span id=\""+counterId+"\" class=\"control-counter\"></span>";
html += "<span id=\""+nextId+"\" class=\"control-next\"><a href=\"javascript:void(0);\">"+ options.nextText +"</a></span>";
html += "</div>";
$(obj).append(html);
};
// add function to anchor image wrapper
$("img", obj).wrap("<a href=\"javascript:void(0);\"></a>");
$("li a", obj).click(function(){
animate("next",true);
});
// add function to next/prev buttons
$("a","#"+nextId).click(function(){
animate("next",true);
});
$("a","#"+prevId).click(function(){
animate("prev",true);
});
// add actual value for the counter
updateCountDisplay();
/* --------------------------------------------------------------------------
=functions
--------------------------------------------------------------------------- */
function updateCountDisplay(){
$("#"+counterId).empty();
$("#"+counterId).append(countCurrent+"/"+countTotal);
}
function adjust(){
if(t>ts) t=0;
if(t<0) t=ts;
$("ul",obj).css("margin-left",(t*w*-1));
clickable = true;
};
function animate(dir,clicked){
if (clickable){
clickable = false;
var ot = t;
switch(dir){
case "next":
countCurrent = (countCurrent>=countTotal) ? 1 : countCurrent+1;
t = (ot>=ts) ? (options.continuous ? t+1 : ts) : t+1;
break;
case "prev":
countCurrent = (countCurrent<=1) ? countTotal : countCurrent-1;
t = (t<=0) ? (options.continuous ? t-1 : 0) : t-1;
break;
default:
t = dir;
break;
};
// update counter
updateCountDisplay();
var diff = Math.abs(ot-t);
var speed = diff*options.speed;
p = (t*w*-1);
$("ul",obj).animate(
{ marginLeft: p },
{ queue:false, duration:speed, complete:adjust }
);
if(!options.continuous && options.controlsFade){
if(t==ts){
$("a","#"+nextId).hide();
} else {
$("a","#"+nextId).show();
};
if(t==0){
$("a","#"+prevId).hide();
} else {
$("a","#"+prevId).show();
};
};
if(clicked) clearTimeout(timeout);
if(options.auto && dir=="next" && !clicked){;
timeout = setTimeout(function(){
animate("next",false);
},diff*options.speed+options.pause);
};
};
};
/* --------------------------------------------------------------------------
=init
--------------------------------------------------------------------------- */
var timeout;
if(options.auto){;
timeout = setTimeout(function(){
animate("next",false);
},options.pause);
};
if(!options.continuous && options.controlsFade){
$("a","#"+prevId).hide();
};
});
};
})(jQuery);
MASTER.JS
Code (php)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Setup varianle
var animationSpeed = 500;
var scrollSpeed = 500;
var fadeDelay = 100;
var currentWork = "";
var nextWork = "";
/* --------------------------------------------------------------------------
=functions
--------------------------------------------------------------------------- */
function getWorkDetails(project) {
return $("#work-"+project);
}
function getWorkLink(project) {
return $("#projectbox-"+project+" a");
}
function showWorkDetails(project, animate) {
if ($("#projectbox a.selected").attr("href")) {
currentWork = getWorkDetails($("#projectbox a.selected").attr("href").replace("\#",""));
}
nextWork = getWorkDetails(project);
if (!getWorkLink(project).hasClass("selected")) {
// dynamically add all images for selected project
$.each(projectImages[project], function(i, projectImage) {
loadProjectImage("img/"+projectImages[project][i].file, projectImages[project][i].alt, $(".project-image-"+project+"-"+(i*1+1)));
});
// fade out displayed work, if it exists
if (currentWork) {currentWork.fadeOut(animationSpeed);}
// fade in selected work
nextWork.delay(fadeDelay).fadeIn(animationSpeed);
// set selected flag
$("#projectbox a.selected").removeClass("selected");
getWorkLink(project).addClass("selected");
// change height of work
$("#work-container").animate({
height: nextWork.outerHeight()
}, scrollSpeed );
// fade in close project button
$("#close").fadeIn(animationSpeed);
// fade in work title the lazy way
$("#work-name").fadeOut(animationSpeed/2);
$("#work-name").empty();
$("#work-name").append(" / "+$("h2", getWorkDetails(project)).text());
$("#work-name").fadeIn(animationSpeed/2);
}
// scroll to top of work
$.scrollTo("#work", scrollSpeed);
}
function hideWorkDetails() {
currentWork = getWorkDetails($("#projectbox a.selected").attr("href").replace("\#",""));
// fade out displayed work
currentWork.fadeOut(animationSpeed);
// remove selected flag
$("#projectbox a.selected").removeClass("selected");
// hide work section
$("#work-container").delay(fadeDelay).animate({
height: 0
}, animationSpeed );
// fade out close project button
$("#close").fadeOut(animationSpeed);
// fade out work title
$("#work-name").fadeOut(animationSpeed);
// update document title
document.title = companyName;
}
function setupCloseProjectButton() {
$("#work").append("<p id=\"close\"><a href=\"#index\">Close Project</a></p>");
$("#close").click(function() {
hideWorkDetails();
});
}
function setUpProjectImages() {
$.each(projectImages, function(project, projectImages) {
$.each(projectImages, function(i, projectImage) {
if (i>0) {
$(".sliderbox ul", getWorkDetails(project)).append("<li><img src=\"img/loading.gif\" alt=\"empty\" class=\"empty project-image-"+project+"-"+(i*1+1)+"\" /></li>");
}
});
});
}
function setUpWorkListHook() {
$(".project-name").after("<span class=\"project-extra\"></span>");
}
function setUpProjectSlider() {
$("#projectbox a").each(function(){
var project = $(this).attr("href").replace("\#","");
// fragile
$(".sliderbox", getWorkDetails(project)).easySlider({
speed: animationSpeed,
project: project
});
});
}
function loadProjectImage(src, alt, target) {
if ($(target).hasClass("empty")) {
$("<img />")
.attr("src", src)
.attr("alt", alt)
.bind("imgload",
function() {
target.before($(this))
.fadeOut(animationSpeed*0,
function() {
target.remove();
}
);
}
);
}
}
/* --------------------------------------------------------------------------
=onload
--------------------------------------------------------------------------- */
$(function() {
// update ids so that scroll animation works
$(".work-details").each(function(){
$(this).attr("id","work-"+$(this).attr("id"));
});
// on click events for showing work
$("#projectbox a").click(function() {
showWorkDetails($(this).attr("href").replace("\#",""));
});
// setup
setupCloseProjectButton();
setUpProjectImages();
setUpWorkListHook();
setUpProjectSlider();
// display work if there is a valid hash in the url
var project = location.hash.replace("\#","");
if (getWorkDetails(project).length) {
showWorkDetails(project, true);
}
});
var animationSpeed = 500;
var scrollSpeed = 500;
var fadeDelay = 100;
var currentWork = "";
var nextWork = "";
/* --------------------------------------------------------------------------
=functions
--------------------------------------------------------------------------- */
function getWorkDetails(project) {
return $("#work-"+project);
}
function getWorkLink(project) {
return $("#projectbox-"+project+" a");
}
function showWorkDetails(project, animate) {
if ($("#projectbox a.selected").attr("href")) {
currentWork = getWorkDetails($("#projectbox a.selected").attr("href").replace("\#",""));
}
nextWork = getWorkDetails(project);
if (!getWorkLink(project).hasClass("selected")) {
// dynamically add all images for selected project
$.each(projectImages[project], function(i, projectImage) {
loadProjectImage("img/"+projectImages[project][i].file, projectImages[project][i].alt, $(".project-image-"+project+"-"+(i*1+1)));
});
// fade out displayed work, if it exists
if (currentWork) {currentWork.fadeOut(animationSpeed);}
// fade in selected work
nextWork.delay(fadeDelay).fadeIn(animationSpeed);
// set selected flag
$("#projectbox a.selected").removeClass("selected");
getWorkLink(project).addClass("selected");
// change height of work
$("#work-container").animate({
height: nextWork.outerHeight()
}, scrollSpeed );
// fade in close project button
$("#close").fadeIn(animationSpeed);
// fade in work title the lazy way
$("#work-name").fadeOut(animationSpeed/2);
$("#work-name").empty();
$("#work-name").append(" / "+$("h2", getWorkDetails(project)).text());
$("#work-name").fadeIn(animationSpeed/2);
}
// scroll to top of work
$.scrollTo("#work", scrollSpeed);
}
function hideWorkDetails() {
currentWork = getWorkDetails($("#projectbox a.selected").attr("href").replace("\#",""));
// fade out displayed work
currentWork.fadeOut(animationSpeed);
// remove selected flag
$("#projectbox a.selected").removeClass("selected");
// hide work section
$("#work-container").delay(fadeDelay).animate({
height: 0
}, animationSpeed );
// fade out close project button
$("#close").fadeOut(animationSpeed);
// fade out work title
$("#work-name").fadeOut(animationSpeed);
// update document title
document.title = companyName;
}
function setupCloseProjectButton() {
$("#work").append("<p id=\"close\"><a href=\"#index\">Close Project</a></p>");
$("#close").click(function() {
hideWorkDetails();
});
}
function setUpProjectImages() {
$.each(projectImages, function(project, projectImages) {
$.each(projectImages, function(i, projectImage) {
if (i>0) {
$(".sliderbox ul", getWorkDetails(project)).append("<li><img src=\"img/loading.gif\" alt=\"empty\" class=\"empty project-image-"+project+"-"+(i*1+1)+"\" /></li>");
}
});
});
}
function setUpWorkListHook() {
$(".project-name").after("<span class=\"project-extra\"></span>");
}
function setUpProjectSlider() {
$("#projectbox a").each(function(){
var project = $(this).attr("href").replace("\#","");
// fragile
$(".sliderbox", getWorkDetails(project)).easySlider({
speed: animationSpeed,
project: project
});
});
}
function loadProjectImage(src, alt, target) {
if ($(target).hasClass("empty")) {
$("<img />")
.attr("src", src)
.attr("alt", alt)
.bind("imgload",
function() {
target.before($(this))
.fadeOut(animationSpeed*0,
function() {
target.remove();
}
);
}
);
}
}
/* --------------------------------------------------------------------------
=onload
--------------------------------------------------------------------------- */
$(function() {
// update ids so that scroll animation works
$(".work-details").each(function(){
$(this).attr("id","work-"+$(this).attr("id"));
});
// on click events for showing work
$("#projectbox a").click(function() {
showWorkDetails($(this).attr("href").replace("\#",""));
});
// setup
setupCloseProjectButton();
setUpProjectImages();
setUpWorkListHook();
setUpProjectSlider();
// display work if there is a valid hash in the url
var project = location.hash.replace("\#","");
if (getWorkDetails(project).length) {
showWorkDetails(project, true);
}
});
Gewijzigd op 03/03/2012 11:36:37 door Casper B