Last active
March 8, 2017 07:45
-
-
Save mohhasbias/259314f2006a91b33012a72e75e8420c to your computer and use it in GitHub Desktop.
Load images from JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node_modules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
v6.5.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Slideshow</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.min.css"> | |
</head> | |
<body> | |
<div id="slider"></div> | |
<script src="node_modules/jquery/dist/jquery.min.js"></script> | |
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script> | |
<script src="main.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function renderSlider(playlist){ | |
return `<div class="carousel slide" data-ride="carousel" data-interval="1000"> | |
<div class="carousel-inner">` + | |
playlist.map((item, index) => ` | |
<div class="item ${index === 0? 'active' : ''}"> | |
<img src="${item.url}" alt="image1"> | |
</div> | |
`) + | |
`</div> | |
</div>`; | |
} | |
$.getJSON('playlist.json') | |
.done(function(playlist) { | |
console.log(playlist); | |
$('#slider').html(renderSlider(playlist)); | |
$('#slider .carousel').carousel({ | |
interval: 1000, | |
pause: null | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "displayer", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"bootstrap": "^3.3.7", | |
"jquery": "^3.1.1" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"url": "http://madingkampus.com/pamflet/17-03-02-madingkampus-kpjlhlefqa-.jpeg", | |
"type": "image/jpeg", | |
"duration": 1 | |
}, | |
{ | |
"url": "http://madingkampus.com/pamflet/17-02-21-madingkampus-alkacgapjf-.PNG", | |
"type": "image/png", | |
"duration": 1 | |
}, | |
{ | |
"url": "http://madingkampus.com/pamflet/17-01-17-madingkampus-kqdeqhgnne-.png", | |
"type": "image/png", | |
"duration": 1 | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment