(Utilizing Tailwind CSS)
Executing my AJAX request:
var urlPost = "assets/js/imgStock.json"
$.ajax({
type: 'GET',
url: urlPost,
success: function (data) {
$.each(data, function (key, value) {
createPostItem(value.name, value.image, value.madeFor, value.size);
if(value.size == 'story'){
$('.img-size').css("height", "472")
$('.img-size').css("height", "270")
} else {
$('.img-size').css("height", "270px")
$('.img-size').css("width", "270px")
}
// $('#'+value.size).addClass("img-post")
});
}
});
Function to generate HTML elements:
function createPostItem(name,image, madeFor, size) {
var html = '<div class="imgStock w-full border-4 my-auto border-blue-500 lg:mx-2 mt-4 mx-auto">' +
'<div class="flex post text-gray-200 animate__animated animate__fadeIn">' +
'<div class="img-size mx-auto relative transition duration-300 ease-in transform hover:-translate-y-2">' +
'<img class="rounded shadow-2xl" src="' + image + '" alt="' + name + '"' +
'<div class="btn-i absolute ">' +
'<div class="btn-i absolute text-center pt-2 animate__animated animate__fadeInLeft pl-2">' + name + '</div>' +
'<span class="flex absolute font-semibold tracking-wide justify-center absolute-pill px-1 text-xxs bg-yellow-400 text-gray-900 rounded-full text-xs">' + madeFor + '</span>' +
'</div>' +
'</div>' +
'</div>' +
'</div>';
$(".images-array").append(html);
}
Document JSON:
[
{
"name": "Calendrier Sofiane Boufal",
"image": "img/Boufal_Story.jpg",
"size": "story",
"madeFor": "Asala Finances"
},
{
"name": "Cover fictive rap",
"image": "img/Roshi_Cover.jpg",
"size": "post",
"madeFor": "Captain Roshi"
},
{
"name": "Calendrier Jean-Pierre Nsame",
"image": "img/mars_nsame.jpg",
"size": "story",
"madeFor": "Asala Finances"
},
{
"name": "Anniveraire Houboulang Mendes",
"image": "img/Mendes-Birthday.jpg",
"size": "story",
"madeFor": "Asala Finances"
}
]
I have adjusted my conditions (if, else) to apply the CSS classes accordingly. Although I encountered issues with identical IDs for multiple images, I am still troubleshooting.
Displayed result: (Images with value.size == "story" are the larger ones - namely: Calendrier Southampton, Calendrier Young Boys, and Happy Birthday)
View image description here