Skip to content

Instantly share code, notes, and snippets.

@ashumeow
Forked from mediaupstream/example.js
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashumeow/9d992773a731a7e099bd to your computer and use it in GitHub Desktop.
Save ashumeow/9d992773a731a7e099bd to your computer and use it in GitHub Desktop.
/**
* file: images.json
*/
{
"images": [
{"title": "Image One", "url": "image1.jpg", "rating": "3.5"},
{"title": "Image Two", "url": "image2.jpg", "rating": "1"},
{"title": "Image Three", "url": "image3.jpg", "rating": "5"}
]
}
/**
* file: application.js
*/
function loadImages (url, container){
// get the JSON object
$.getJSON(url, function(data){
if(typeof data === 'object'){
// create the HTML markup for the slider from data
$.each(data['images'], function(key, image){
var slide = '<li><img src="'+image['url']+'" alt="'+image['title']+'"></li>';
$(container).append(slide);
});
// initialize anythingSlider
$(container).anythingSlider();
}
});
};
$(function(){
loadImages('images.json', '#slider1');
});
/**
* file: index.html
*/
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
<script src="http://proloser.github.com/AnythingSlider/js/jquery.anythingslider.js"></script>
<script src="application.js"></script>
</head>
<body>
<ul id="slider1"></ul>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment