python-gallery/gallery/templates/index.html

41 lines
1.5 KiB
HTML
Raw Normal View History

2022-12-01 18:48:31 +00:00
{% extends 'layout.html' %}
{% block nav_home %}navigation-item__selected{% endblock %}
{% block wrapper_class %}index-wrapper{% endblock %}
2022-12-01 18:48:31 +00:00
{% block content %}
<div class="gallery">
{% for image in images %}
<a id="image-{{ image['id'] }}" class="gallery__item" href="/image/{{ image['id'] }}">
<span class="gallery__item-info">
<p>{{ image['id'] }}</p>
<h2>{{ image['created_at'] }}</h2>
</span>
<img
class="gallery__item-image"
src="/api/uploads/{{ image['file_name'] }}/400"
onload="imgFade(this)"
style="opacity:0;"
loading="lazy"
/>
</a>
{% endfor %}
2022-12-01 18:48:31 +00:00
</div>
{% endblock %}
{% block script %}
2022-12-01 18:48:31 +00:00
<script>
const urlParams = new URLSearchParams(window.location.search);
const src = urlParams.get('src');
if (src) {
var imgOffset = document.getElementById('image-' + src).offsetTop;
var imgHeight = document.getElementById('image-' + src).offsetHeight;
var windowHeight = window.innerHeight;
document.querySelector('html').style.scrollBehavior = 'auto';
window.scrollTo(0, imgOffset + (imgHeight / 2) - (windowHeight / 2));
document.querySelector('html').style.scrollBehavior = 'smooth';
2022-12-14 19:55:40 +00:00
}
2022-12-01 18:48:31 +00:00
</script>
{% endblock %}