JSFiddle - React, Tailwind, and code Playground
by codendive
HTML
<body>
<header>
<div class="top-tracks-text-div">
<h1>Top Tracks</h1>
</div>
</header>
<main>
<div class="wrapper">
</div>
</main>
<footer>
</footer>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript" src="js/script.js"></script>
</body>
CSS
body {
height: 100%;
background-image: url("../img/old-candle.jpg");
background-repeat: no-repeat;
margin: 0;
background-size: 100% 100%;
}
header {
text-align: center;
}
.top-tracks-text-div {
width: 30%;
padding: .1% 2%;
background-color: rgba(255,255,255,.09);
background-image: url("../img/div-background.jpg");
background-size: cover;
display: inline-block;
border-radius: 20px;
border: solid 2px black;
margin: 20px 0 10px;
}
h1 {
text-align: center;
font-family: sans-serif;
color: rgba(0, 0, 0,.9);
text-shadow: 2px 2px rgba(255, 255, 255, .4);
font-size: 3rem;
margin: 0;
}
main {
width: 100%;
height: 100vh;
margin: 0 ;
text-align: center;
background-color: rgba(0,0,0,.45);
}
.wrapper {
height: 90%;
}
ul {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
padding-left: 0;
height: 100%;
padding-top: 20px;
margin-bottom: 0;
}
li {
list-style: none;
width: 170px;
height: 170px;
margin: 0 30px 30px;
background-color: lightblue;
}
img {
width: 100%;
height: 100%;
}
p {
color: white;
}
.album-text {
font-size: 25px;
font-style: bold;
color: rgba(255, 170, 0, .6);
;
}
.album-title-label {
font-size: 10px ;
margin-left: 10px;
color: white;
}
footer {
height: 150px;
background-color: black;
}
JavaScript
$(document).ready(function(){
var spotify = "https://api.spotify.com/v1/artists/4EVpmkEwrLYEg6jIsiPMIb/top-tracks?country=US";
var displayPhotos = function(data){
var html = '<ul>';
$.each(data.tracks, function(i,eachTrack){
html += '<li>';
html += '<a href="' + eachTrack.album.images[1].url + '">';
html += '<img src="' + eachTrack.album.images[1].url + '">';
html += '</a>';
html += '<p class="album-text">' + eachTrack.album.name + '<span class="album-title-label">-album</span></p>';
html += '<p>' + eachTrack.name + '</p>';
var ms = eachTrack.duration_ms;
var min = Math.floor(ms / 60000);
var sec = ((ms % 60000) / 1000).toFixed(0);
if(sec < 10){
html += '<p>' + min + ':0' + sec + '</p>';
}
else{
html += '<p>' + min + ':' + sec + '</p>';
}
html += '</li>';
});
html += '</ul>';
$(".wrapper").html(html);
}
$.getJSON(spotify,displayPhotos);
});
$("a").click(function(event){
event.preventDefault();
});