No edit summary |
No edit summary |
||
| Line 46: | Line 46: | ||
// Scroll to the top of the container (position 0) | // Scroll to the top of the container (position 0) | ||
container.animate({ | container.animate({ | ||
scrollTop: twoPosition - | scrollTop: twoPosition - 240 | ||
}, 300); // 300ms animation duration | }, 300); // 300ms animation duration | ||
}); | }); | ||
| Line 57: | Line 57: | ||
// Scroll to the top of the container (position 0) | // Scroll to the top of the container (position 0) | ||
container.animate({ | container.animate({ | ||
scrollTop: threePosition - | scrollTop: threePosition - 275 | ||
}, 300); // 300ms animation duration | }, 300); // 300ms animation duration | ||
}); | }); | ||
}); | }); | ||
Revision as of 17:40, 28 February 2025
$(document).ready(function() {
// Get element's position relative to the viewport
function getElementTopPosition(selector) {
var element = $(selector);
if (element.length) {
var elementPosition = element.offset().top;
var scrollTop = $(window).scrollTop();
var positionInViewport = elementPosition - scrollTop;
// Store the position for later use
var storedPosition = elementPosition;
console.log('Element position stored:', storedPosition);
return storedPosition;
}
return 0;
}
// Store positions when page loads
var onePosition = getElementTopPosition('.sidebar-heading.one');
var twoPosition = getElementTopPosition('.sidebar-heading.two');
var threePosition = getElementTopPosition('.sidebar-heading.three');
// Select elements with the scroll-trigger class
$('.sidebar-heading.one').click(function() {
// Find the scrollable container
var container = $('#topbar');
// Scroll to the top of the container (position 0)
container.animate({
scrollTop: onePosition - 202
}, 300); // 300ms animation duration
});
$('.sidebar-heading.two').click(function() {
// Find the scrollable container
var container = $('#topbar');
// Scroll to the top of the container (position 0)
container.animate({
scrollTop: twoPosition - 240
}, 300); // 300ms animation duration
});
// Select elements with the scroll-trigger class
$('.sidebar-heading.three').click(function() {
// Find the scrollable container
var container = $('#topbar');
// Scroll to the top of the container (position 0)
container.animate({
scrollTop: threePosition - 275
}, 300); // 300ms animation duration
});
});
