diff --git a/css/app.css b/css/app.css index f600dea..6400e89 100644 --- a/css/app.css +++ b/css/app.css @@ -4444,6 +4444,8 @@ article > *:not(.entry-content, .chapter-header-block), height: 2rem; border-radius: 1rem; width: 3px; + /* transition: top 0.3s ease-out; */ + transition: top 0.7s cubic-bezier(0, 0.75, 0.47, 0.99); } .conseils_wrapper .chapter_index a { diff --git a/css/editor-style.css b/css/editor-style.css index b3ba671..b87791b 100644 --- a/css/editor-style.css +++ b/css/editor-style.css @@ -127,10 +127,6 @@ flex-grow: 1 } -.transform { - transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y)) -} - .flex-col { flex-direction: column } diff --git a/js/app.js b/js/app.js index 0a747f5..dbb1981 100644 --- a/js/app.js +++ b/js/app.js @@ -227,8 +227,8 @@ let chapterIndex = document.querySelector(".chapter_index"); let questionBlocks = document.querySelectorAll(".questions-container-block"); function handleLinksBehavior() { - let chapterLinks = document.querySelectorAll(".chapter_index__link"); - chapterLinks.forEach((link) => { + let chapterLinks2 = document.querySelectorAll(".chapter_index__link"); + chapterLinks2.forEach((link) => { link.addEventListener("click", (e) => { e.preventDefault(); let target = e.target.getAttribute("href"); @@ -240,10 +240,44 @@ }); }); } - function handleChapterIndicatorPosition() { - let chapterIndicator = document.querySelector(".chapter_index__position-indicator"); + function handleLinkScrollToTarget(e) { + e.preventDefault(); + let target = e.target.getAttribute("href"); + let targetBlock = document.querySelector(target); + targetBlock.scrollIntoView({ + behavior: "smooth" + }); + targetBlock.focus(); } - handleLinksBehavior(); + function handleChapterIndicatorPosition(targetPosition) { + let chapterIndicator = document.querySelector(".chapter_index__position-indicator"); + chapterIndicator.style.top = targetPosition + "px"; + } + let chapterLinks = document.querySelectorAll(".chapter_index__link"); + chapterLinks.forEach((link) => { + link.addEventListener("click", (e) => { + handleLinkScrollToTarget(e); + handleChapterIndicatorPosition(e.target.offsetTop); + }); + }); + const io = new IntersectionObserver((entries) => { + entries.forEach((entry) => { + if (entry.intersectionRatio > 0) { + entry.target.classList.add("active"); + const blockId = entry.target.getAttribute("id"); + const relatedChapterLink = document.querySelector(`a[href="#${blockId}"]`); + handleChapterIndicatorPosition(relatedChapterLink.offsetTop); + } else { + } + }); + }); + const questionsContainerBlocks = document.querySelectorAll(".questions-container-block"); + const vocabulaireSummaryBlock = document.querySelector(".homegrade-blocks-vocabulaire-summary"); + const allBlocks = [...questionsContainerBlocks, vocabulaireSummaryBlock]; + console.log(vocabulaireSummaryBlock); + allBlocks.forEach((el) => { + io.observe(el); + }); } // resources/js/app.js diff --git a/resources/css/pages/single-conseils.css b/resources/css/pages/single-conseils.css index e4d3fde..be86a8f 100644 --- a/resources/css/pages/single-conseils.css +++ b/resources/css/pages/single-conseils.css @@ -23,6 +23,8 @@ &__position-indicator { @apply h-8 absolute top-0 -left-4 rounded-2xl; width: 3px; + /* transition: top 0.3s ease-out; */ + transition: top 0.7s cubic-bezier(0, 0.75, 0.47, 0.99); } a { diff --git a/resources/js/single-conseil.js b/resources/js/single-conseil.js index 92823bf..f1e6250 100644 --- a/resources/js/single-conseil.js +++ b/resources/js/single-conseil.js @@ -18,12 +18,51 @@ export default function singleConseil() { }); }); } + function handleLinkScrollToTarget(e) { + e.preventDefault(); + let target = e.target.getAttribute('href'); + let targetBlock = document.querySelector(target); - function handleChapterIndicatorPosition() { - let chapterIndicator = document.querySelector('.chapter_index__position-indicator'); + targetBlock.scrollIntoView({ + behavior: 'smooth', + }); + targetBlock.focus(); } - handleLinksBehavior(); + function handleChapterIndicatorPosition(targetPosition) { + let chapterIndicator = document.querySelector('.chapter_index__position-indicator'); + chapterIndicator.style.top = targetPosition + 'px'; + } + + let chapterLinks = document.querySelectorAll('.chapter_index__link'); + + chapterLinks.forEach((link) => { + link.addEventListener('click', (e) => { + handleLinkScrollToTarget(e); + handleChapterIndicatorPosition(e.target.offsetTop); + }); + }); + + // Register IntersectionObserver + const io = new IntersectionObserver((entries) => { + entries.forEach((entry) => { + if (entry.intersectionRatio > 0) { + // Add 'active' class if observation target is inside viewport + entry.target.classList.add('active'); + const blockId = entry.target.getAttribute('id'); + const relatedChapterLink = document.querySelector(`a[href="#${blockId}"]`); + handleChapterIndicatorPosition(relatedChapterLink.offsetTop); + } else { + // Remove 'active' class otherwise + // entry.target.classList.remove('active'); + } + }); + }); + const questionsContainerBlocks = document.querySelectorAll('.questions-container-block'); + const vocabulaireSummaryBlock = document.querySelector('.homegrade-blocks-vocabulaire-summary'); + const allBlocks = [...questionsContainerBlocks, vocabulaireSummaryBlock]; + + console.log(vocabulaireSummaryBlock); + allBlocks.forEach((el) => { + io.observe(el); + }); } -// console.log(chapterIndex); -// console.log(questionBlocks); -// console.log(chapterLinks);