42868d70
andryeyev
Создал GIT
|
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
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us">
<head>
<title>jCarousel Examples</title>
<link href="../style.css" rel="stylesheet" type="text/css" />
<!--
jQuery library
-->
<script type="text/javascript" src="../lib/jquery-1.4.2.min.js"></script>
<!--
jCarousel library
-->
<script type="text/javascript" src="../lib/jquery.jcarousel.min.js"></script>
<!--
jCarousel skin stylesheet
-->
<link rel="stylesheet" type="text/css" href="../skins/ie7/skin.css" />
<style type="text/css">
#mycarousel .jcarousel-item-placeholder {
background: transparent url(images/loading-small.gif) 50% 50% no-repeat;
}
</style>
<script type="text/javascript">
function mycarousel_itemLoadCallback(carousel, state)
{
if (carousel.prevFirst != null) {
// Remove the last visible items to keep the list small
for (var i = carousel.prevFirst; i <= carousel.prevLast; i++) {
// jCarousel takes care not to remove visible items
carousel.remove(i);
}
}
var per_page = carousel.last - carousel.first + 1;
var currPage = 0;
var f,l;
var cr = carousel;
for (var i = carousel.first; i <= carousel.last; i++) {
var page = Math.ceil(i / per_page);
if (currPage != page) {
currPage = page;
f = ((page - 1) * per_page) + 1;
l = f + per_page - 1;
f = f < carousel.first ? carousel.first : f;
l = l > carousel.last ? carousel.last : l;
if (carousel.has(f, l)) {
continue;
}
mycarousel_makeRequest(carousel, f, l, per_page, page);
}
}
};
function mycarousel_makeRequest(carousel, first, last, per_page, page)
{
// Lock carousel until request has been made
carousel.lock();
jQuery.get(
'dynamic_flickr_api.php',
{
'per_page': per_page,
'page': page
},
function(data) {
mycarousel_itemAddCallback(carousel, first, last, data, page);
},
'xml'
);
};
function mycarousel_itemAddCallback(carousel, first, last, data, page)
{
// Unlock
carousel.unlock();
// Set size
carousel.size($('photos', data).attr('total'));
var photos = $('photo', data);
var per_page = carousel.last - carousel.first + 1;
for (var i = first; i <= last; i++) {
var pos = i - 1;
var idx = Math.round(((pos / per_page) - Math.floor(pos / per_page)) * per_page);
carousel.add(i, mycarousel_getItemHTML(photos.get(idx)));
}
};
/**
* Global item html creation helper.
*/
function mycarousel_getItemHTML(photo)
{
var url = 'http://farm'+$(photo).attr('farm')+'.static.flickr.com/'+$(photo).attr('server')+'/'+$(photo).attr('id')+'_'+$(photo).attr('secret')+'_s.jpg';
return '<a href="http://www.flickr.com/photos/'+$(photo).attr('owner')+'/'+$(photo).attr('id')+'/" target="_blank" title="'+$(photo).attr('title')+'"><img src="' + url + '" border="0" width="75" height="75" alt="'+$(photo).attr('title')+'" /></a>';
};
jQuery(document).ready(function() {
jQuery('#mycarousel').jcarousel({
itemLoadCallback: mycarousel_itemLoadCallback
});
});
</script>
</head>
<body>
<div id="wrap">
<h1>jCarousel</h1>
<h2>Riding carousels with jQuery</h2>
<h3>Carousel with dynamic content loading via Ajax from the Flickr API</h3>
<p>
The data is loaded dynamically from the <a href="http://flickr.com/services/api/">Flickr API</a>
method <a href="http://flickr.com/services/api/flickr.photos.getRecent.html">flickr.photos.getRecent</a>.
All items not in the visible range are removed from the list to keep the list small.
</p>
<p>
Note: There are constantly added new photos at flickr, so you possibly get different photos at certain positions.
</p>
<div id="mycarousel" class="jcarousel-skin-ie7">
<ul>
<!-- The content will be dynamically loaded in here -->
</ul>
</div>
<p>
<strong>If you're using this example on your own server, don't forget to set your API key in dynamic_flickr_api.php!</strong>
</p>
</div>
</body>
</html>
|