Changed fade between html iframe animation

This commit is contained in:
Kevin Veen-Birkenbach 2025-07-07 15:37:24 +02:00
parent d99a8c8452
commit 55d309b2d7
No known key found for this signature in database
GPG Key ID: 44D8F11FD62F878E
2 changed files with 62 additions and 51 deletions

View File

@ -21,71 +21,77 @@ function syncIframeHeight() {
} }
} }
// Function to open a URL in an iframe // Function to open a URL in an iframe (jQuery version mit 1500 ms Fade)
function openIframe(url) { function openIframe(url) {
enterFullscreen() enterFullscreen();
// Hide the container (and its scroll-container) so the iframe can appear in its place
if (scrollbarContainer) {
scrollbarContainer.style.display = 'none';
}
// Hide any custom scrollbar element if present var $container = scrollbarContainer ? $(scrollbarContainer) : null;
if (customScrollbar) { var $customScroll = customScrollbar ? $(customScrollbar) : null;
customScrollbar.style.display = 'none'; var $main = $(mainElement);
}
// Create or retrieve the iframe in the main element // Original-Content ausblenden mit 1500 ms
let iframe = mainElement.querySelector("iframe"); var promises = [];
if (!iframe) { if ($container) promises.push($container.fadeOut(1500).promise());
iframe = document.createElement("iframe"); if ($customScroll) promises.push($customScroll.fadeOut(1500).promise());
iframe.width = "100%";
iframe.style.border = "none";
iframe.style.overflow = "auto"; // Enable internal scrolling
iframe.scrolling = "auto";
mainElement.appendChild(iframe);
syncIframeHeight();
}
// Set the iframe's source URL $.when.apply($, promises).done(function() {
iframe.src = url; // Iframe anlegen, falls noch nicht vorhanden
var $iframe = $main.find('iframe');
if ($iframe.length === 0) {
originalMainStyle = $main.attr('style') || null;
$iframe = $('<iframe>', {
width: '100%',
frameborder: 0,
scrolling: 'auto'
}).css({ overflow: 'auto', display: 'none' });
$main.append($iframe);
}
// Push the new URL state without reloading the page // Quelle setzen und mit 1500 ms einblenden
const newUrl = new URL(window.location); $iframe
newUrl.searchParams.set('iframe', url); .attr('src', url)
window.history.pushState({ iframe: url }, '', newUrl); .fadeIn(1500, function() {
syncIframeHeight();
});
// URL-State pushen
var newUrl = new URL(window.location);
newUrl.searchParams.set('iframe', url);
window.history.pushState({ iframe: url }, '', newUrl);
});
} }
// Function to restore the original content and show the container again // Function to restore the original content (jQuery version mit 1500 ms Fade)
function restoreOriginal() { function restoreOriginal() {
// Remove the iframe from the DOM var $main = $(mainElement);
const iframe = mainElement.querySelector("iframe"); var $iframe = $main.find('iframe');
if (iframe) { var $container = scrollbarContainer ? $(scrollbarContainer) : null;
iframe.remove(); var $customScroll = customScrollbar ? $(customScrollbar) : null;
}
// Show the original container if ($iframe.length) {
if (scrollbarContainer) { // Iframe mit 1500 ms ausblenden, dann entfernen und Original einblenden
scrollbarContainer.style.display = ''; $iframe.fadeOut(1500, function() {
} $iframe.remove();
// Restore any custom scrollbar if ($container) $container.fadeIn(1500);
if (customScrollbar) { if ($customScroll) $customScroll.fadeIn(1500);
customScrollbar.style.display = '';
}
// Restore the original inline style of the main element // Inline-Style des main-Elements zurücksetzen
if (originalMainStyle !== null) { if (originalMainStyle !== null) {
mainElement.setAttribute("style", originalMainStyle); $main.attr('style', originalMainStyle);
} else { } else {
mainElement.removeAttribute("style"); $main.removeAttr('style');
} }
// Update the URL to remove the iframe parameter // URL-Parameter entfernen
const newUrl = new URL(window.location); var newUrl = new URL(window.location);
newUrl.searchParams.delete("iframe"); newUrl.searchParams.delete('iframe');
window.history.pushState({}, '', newUrl); window.history.pushState({}, '', newUrl);
});
}
} }
// Initialize event listeners after DOM content is loaded // Initialize event listeners after DOM content is loaded
document.addEventListener("DOMContentLoaded", function() { document.addEventListener("DOMContentLoaded", function() {
// Cache references to elements and original state // Cache references to elements and original state

View File

@ -20,6 +20,11 @@
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<link rel="stylesheet" href="{{ url_for('static', filename='css/default.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='css/default.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/custom_scrollbar.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='css/custom_scrollbar.css') }}">
<!-- JQuery -->
<script
src="https://code.jquery.com/jquery-3.6.0.min.js"
crossorigin="anonymous">
</script>
</head> </head>
<body <body
{% if apod_bg %} {% if apod_bg %}