python-gallery/templates/home.html

54 lines
1.7 KiB
HTML
Raw Normal View History

2022-12-01 18:48:31 +00:00
{% extends 'layout.html' %}
{% block content %}
<header>
<img src="{{ url_for('static', filename='images/leaves.jpg') }}" alt="leaves"/>
<span></span>
</header>
<div class="app">
2022-12-14 19:55:40 +00:00
<h1>Gallery</h1>
2022-12-01 18:48:31 +00:00
<div id="gallery" class="gallery"></div>
</div>
<script>
2022-12-14 19:55:40 +00:00
let imageList = [];
let imageIndex = 0;
2022-12-19 15:07:41 +00:00
2022-12-19 21:15:56 +00:00
function loadMore(startIndex, amount = 20) {
2022-12-14 19:55:40 +00:00
for (let i = startIndex; i < startIndex + amount; i++) {
if (i < imageList.length) {
2022-12-19 21:15:56 +00:00
loadImg(imageList[i][0], imageList[i][1]);
2022-12-14 19:55:40 +00:00
}
}
imageIndex = startIndex + amount;
2022-12-14 19:55:40 +00:00
}
function loadImg(id, fileName) {
var imgDiv = `
<a class="gallery__item" href="/image/${id}">
<div class="gallery__item-info">
<p>${id}</p>\
<h2>${fileName}</h2>
</div>
<span class="gallery__item-filter"></span>
<img class="gallery__item-image" src="/uploads/original/${fileName}" onload="imgFade(this)" style="display:none;">
</a>
`;
$(imgDiv).hide().appendTo('#gallery').fadeIn(250);
}
2022-12-01 18:48:31 +00:00
$.ajax({
2022-12-14 19:55:40 +00:00
url: '/fileList/original',
2022-12-01 18:48:31 +00:00
type: 'get',
success: function(response) {
2022-12-14 19:55:40 +00:00
imageList = response;
2022-12-19 21:15:56 +00:00
loadMore(0, 30);
2022-12-14 19:55:40 +00:00
}
});
$(window).scroll(function() {
2022-12-19 21:15:56 +00:00
if ($(window).height() + $(window).scrollTop() >= $(document).height() - 500) {
2022-12-14 19:55:40 +00:00
loadMore(imageIndex);
2022-12-01 18:48:31 +00:00
}
});
</script>
{% endblock %}