-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
69 lines (51 loc) · 1.57 KB
/
script.js
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
"use strict";
var container = document.getElementById('container');
var viewport = document.getElementById('viewport');
var indexCounter = 0;
var indexMax = 0;
function nextImage() {
indexCounter += 1;
if ( indexCounter > indexMax) {
indexCounter=0;
}
showImage(indexCounter);
}
function showImage(index) {
var offset = index * viewport.clientWidth;
console.log('viewportw: ' + viewport.clientWidth + ' offset: ' + offset);
container.style.marginLeft = '-' + offset + 'px';
indexCounter = index;
}
function apiSuccess(result){
// debugger;
var photos = result['items'];
indexMax = photos.length-1;
for (var i = photos.length - 1; i >= 0; i--) {
var currentPhoto = photos[i];
var imageSrc = currentPhoto['media']['m'];
// console.log(imageSrc);
var henrysImage = new Image();
henrysImage.src = imageSrc;
var henrysDiv = document.createElement('div');
henrysDiv.appendChild(henrysImage);
henrysDiv.className = 'post';
henrysDiv.style.width= viewport.clientWidth + 'px';
container.appendChild(henrysDiv);
};
}
function getPosts(){
// Settings to pass to jquery to fetch the data
var ajaxSettings = {
// The url to flickrs api
url: 'http://api.flickr.com/services/feeds/photos_public.gne?format=json&jsoncallback=?',
// The format we want it in
dataType: 'jsonp',
// The function to execute when the api has finished loading
success: apiSuccess,
};
// Pass all the settings to being fetching the data
jQuery.ajax(ajaxSettings);
}
jQuery(document).ready(function(){
getPosts();
});