$(document).ready(function () { $(".logo-slider").slick({ autoplay: false, autoplaySpeed: 7000, dots: true, arrows: false, infinite: false, centerMode: false, slidesToShow: 1, slidesToScroll: 1, centerPadding: "0", variableWidth: false, responsive: [ { breakpoint: 767, settings: { slidesToShow: 1, slidesToScroll: 1, }, }, ], }); // Accordion functionality - optimized to batch DOM operations $(".accordion-header").click(function () { var accordionItem = $(this).parent(); var accordionContent = accordionItem.find(".accordion-content"); var isActive = accordionItem.hasClass("active"); // Toggle the clicked item - batch DOM operations if (isActive) { // Close accordion - batch writes requestAnimationFrame(function() { accordionItem.removeClass("active"); accordionItem.attr("aria-expanded", "false"); accordionContent.css("max-height", "0"); }); } else { // Open accordion with dynamic height - batch reads first // Temporarily clone content to measure height without affecting display var tempContent = accordionContent.clone(); tempContent.css({ position: "absolute", visibility: "hidden", "max-height": "none", height: "auto", "padding-bottom": "0", overflow: "visible", }); accordionContent.parent().append(tempContent); // Batch all layout reads var contentHeight = tempContent.prop("scrollHeight"); var tempContentOffset = tempContent.offset().top; // Calculate the total height including all child elements and their margins var totalHeight = 0; tempContent.find("*").each(function () { var $this = $(this); var elementHeight = $this.outerHeight(true); // Includes margin var elementTop = $this.offset().top; if (elementHeight > 0 && elementTop >= tempContentOffset) { var elementBottom = elementTop + elementHeight; var relativeBottom = elementBottom - tempContentOffset; totalHeight = Math.max(totalHeight, relativeBottom); } }); // Also check for any elements that might extend beyond the normal flow var maxBottom = 0; var tempRect = tempContent[0].getBoundingClientRect(); tempContent.find("*").each(function () { var rect = this.getBoundingClientRect(); var relativeBottom = rect.bottom - tempRect.top; maxBottom = Math.max(maxBottom, relativeBottom); }); // Use the largest calculated height var calculatedHeight = Math.max(contentHeight, totalHeight, maxBottom); tempContent.remove(); // Add generous extra padding to ensure content is fully visible var finalHeight = calculatedHeight + 150; // Increased to 150px padding // Batch DOM writes using requestAnimationFrame requestAnimationFrame(function() { accordionItem.addClass("active"); accordionItem.attr("aria-expanded", "true"); accordionContent.css("max-height", finalHeight + "px"); }); } }); // Keyboard accessibility $(".accordion-header").keydown(function (e) { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); $(this).click(); } }); });