Widget:SSMedalBox
Jump to navigation
Jump to search
<script> $(document).ready(function() {
var containerMedals = document.querySelector('.containerMedals'); var fixedContainerClass = 'fixedContainer'; var wrapper = null; var placeholder = null; var originalParent = containerMedals.parentNode; var originalNextSibling = containerMedals.nextSibling; var originalBottom = containerMedals.getBoundingClientRect().bottom + window.scrollY;
window.addEventListener('scroll', function() { var scrollPosition = window.scrollY || document.documentElement.scrollTop;
if (scrollPosition >= originalBottom) { // Check if the scroll position is past the bottom of containerMedals if (!wrapper) { // Create a wrapper div with the fixedContainer class wrapper = document.createElement('div'); wrapper.classList.add(fixedContainerClass);
// Create a placeholder div with the same height as containerMedals placeholder = document.createElement('div'); placeholder.style.height = containerMedals.offsetHeight + 'px';
// Insert the placeholder in the original position originalParent.insertBefore(placeholder, containerMedals);
// Move containerMedals into the wrapper containerMedals.parentNode.insertBefore(wrapper, containerMedals); wrapper.appendChild(containerMedals); } } else if (scrollPosition < originalBottom) { if (wrapper) { // Move containerMedals back to its original position originalParent.insertBefore(containerMedals, placeholder); originalParent.removeChild(placeholder); wrapper.parentNode.removeChild(wrapper); wrapper = null; placeholder = null; } } });
}); </script>