Remember scroll position, and automatically scroll to bottom page when

print button appears
This commit is contained in:
TT-392 2024-11-25 19:17:31 +01:00
parent df9b93e2da
commit 1746db8e37
2 changed files with 19 additions and 3 deletions

7
app.py
View file

@ -48,8 +48,8 @@ templates = {
}
def render_text_template(info=None, info_color=None):
return render_template('text.html', filename=session["text image path"], text1=session["text1"], text2=session["text2"], cut=session["cut"], info=info, info_color=info_color)
def render_text_template(info=None, info_color=None, scrollDown=None):
return render_template('text.html', filename=session["text image path"], text1=session["text1"], text2=session["text2"], cut=session["cut"], info=info, info_color=info_color, scrollDown=scrollDown)
@ -176,10 +176,11 @@ def text_form():
session["text image path"] = text_image_filename
img.save(get_file_path(session, session["text image path"]))
print()
print(session["text image path"])
return render_text_template()
return render_text_template(scrollDown = True)
@app.route('/text', methods=['GET', 'POST'])

View file

@ -82,6 +82,21 @@
</head>
<body>
<script>
{% if scrollDown %}
localStorage.setItem('scrollpos', 99999);
{% endif %}
document.addEventListener("DOMContentLoaded", function(event) {
var scrollpos = localStorage.getItem('scrollpos');
if (scrollpos) window.scrollTo(0, scrollpos);
});
window.onbeforeunload = function(e) {
localStorage.setItem('scrollpos', window.scrollY);
};
</script>
<div class="container">
<a href="text" class="box">
<div>Text</div>