Skip to content

Commit

Permalink
413 make function to expand to make more of the text readeble when pr…
Browse files Browse the repository at this point in the history
…essing read more contact us page (#434)

* Added expand text functionality to "read more" sections.

* Removed test text.
  • Loading branch information
juliehabb authored Apr 11, 2024
1 parent e861918 commit f4d1aa0
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 22 deletions.
22 changes: 22 additions & 0 deletions js/general.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

//Expands text when clicking on button:
export function toggleTextOverflow(sectionContainer, textContainer, showMoreBtn) {
showMoreBtn.addEventListener("click", () => {
textContainer.classList.toggle("overflow-auto");
//Closed
if (textContainer.classList.contains("overflow-auto")) {
textContainer.style.overflow = "auto";
textContainer.style.maxHeight = "";
showMoreBtn.textContent = "READ MORE";
sectionContainer.style.height = "auto";
} else { //Open
let textContentHeight = textContainer.scrollHeight;
textContainer.style.maxHeight = textContentHeight + "px";
textContainer.style.overflow = "";
showMoreBtn.textContent = "READ LESS";
sectionContainer.style.height = "auto";
}
});
}


25 changes: 25 additions & 0 deletions js/ourWork.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { toggleTextOverflow } from "./general.mjs";

//Makes the specific Id's of the elements as arguments.
function addReadMoreSections(sectionContainerId, textContainerId, showMoreBtnId) {
let sectionContainer = document.getElementById(sectionContainerId);
let textContainer = document.querySelector(textContainerId);
let showMoreBtn = document.querySelector(showMoreBtnId);
toggleTextOverflow(sectionContainer, textContainer, showMoreBtn);
}

//Add toggleTextOverflow functionality to individual sections:
//Healthcare section
addReadMoreSections("section-container", "#scroll-container-health", "#read-more-btn");
//Education section
addReadMoreSections("section-container-edu", "#scroll-container-edu", "#read-more-btn-edu");
// Living situation section
addReadMoreSections("section-container-lisi", "#scroll-container-lisi", "#read-more-btn-lisi");
//Food Distribution section
addReadMoreSections("section-container-food", "#scroll-container-food", "#read-more-btn-food");
//Music Lessong section
readMore("section-container-music", "#scroll-container-music", "#read-more-btn-music");
//Future goals section
addReadMoreSections("section-container-futuregoals", "#scroll-container-futuregoals", "#read-more-btn-futuregoals");
//Activities section
addReadMoreSections("section-container-activities", "#scroll-container-activities", "#read-more-btn-activities");
46 changes: 24 additions & 22 deletions pages/our-work.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
crossorigin="anonymous"
referrerpolicy="no-referrer"
/>
<script defer type="module" src="/js/ourWork.mjs"></script>

</head>
<body>

Expand Down Expand Up @@ -373,7 +375,7 @@ <h1 class="font-justAnotherHand text-[200px] tracking-widest text-white text-cen

<!-- Section 2 -->
<section class="mx-[120px] mb-20">
<div class="flex justify-center items-center w-full h-[576px] gap-8 my-8">
<div class="flex justify-center items-center w-full h-[576px] gap-8 my-8" id="section-container">
<div class="max-w-[574px] max-h-[576px] overflow-hidden">
<img
src="/assets/placeholder-images/IMG_5348.webp"
Expand All @@ -384,9 +386,9 @@ <h1 class="font-justAnotherHand text-[200px] tracking-widest text-white text-cen
<div class="text-button-container flex-col">
<h2 class="font-sans text-[54px] font-medium">Healthcare</h2>
<div
class="scroll-container max-w-[574px] max-h-[210px] overflow-auto"
class="scroll-container max-w-[574px] max-h-[210px] overflow-auto" id="scroll-container-health"
>
<p class="scroll-content font-sans text-lg">
<p class="scroll-content font-sans text-lg" id="scroll-content">
In Madagascar, child mortality is high and many die from diseases
that can be easily treated with modern medicine. Typical causes
are infectious diseases such as pneumonia, tuberculosis, diarrheal
Expand All @@ -400,13 +402,13 @@ <h2 class="font-sans text-[54px] font-medium">Healthcare</h2>
</p>
</div>
<div class="button-container flex justify-between items-start mt-10">
<button class="reg-button bg-black text-white">READ MORE</button>
<button class="reg-button bg-black text-white" id="read-more-btn">READ MORE</button>
<button class="reg-button bg-[#EE6352] text-white">DONATE</button>
</div>
</div>
</div>
<div
class="flex flex-row-reverse justify-center items-center w-full h-[576px] gap-8 my-8"
class="flex flex-row-reverse justify-center items-center w-full h-[576px] gap-8 my-8" id="section-container-edu"
>
<div class="max-w-[574px] max-h-[576px] overflow-hidden">
<img
Expand All @@ -418,7 +420,7 @@ <h2 class="font-sans text-[54px] font-medium">Healthcare</h2>
<div class="text-button-container flex-col">
<h2 class="font-sans text-[54px] font-medium">Education</h2>
<div
class="scroll-container max-w-[574px] max-h-[210px] overflow-auto"
class="scroll-container max-w-[574px] max-h-[210px] overflow-auto" id="scroll-container-edu"
>
<p class="scroll-content font-sans text-lg">
Schooling gives children hope for the future. When children lack
Expand Down Expand Up @@ -462,12 +464,12 @@ <h2 class="font-sans text-[54px] font-medium">Education</h2>
</p>
</div>
<div class="button-container flex justify-between items-start mt-10">
<button class="reg-button bg-black text-white">READ MORE</button>
<button class="reg-button bg-black text-white" id="read-more-btn-edu" >READ MORE</button>
<button class="reg-button bg-[#EE6352] text-white">DONATE</button>
</div>
</div>
</div>
<div class="flex justify-center items-center w-full h-[576px] gap-8 my-8">
<div class="flex justify-center items-center w-full h-[576px] gap-8 my-8" id="section-container-lisi">
<div class="max-w-[574px] max-h-[576px] overflow-hidden">
<img
class="object-cover h-[576px]"
Expand All @@ -479,7 +481,7 @@ <h2 class="font-sans text-[54px] font-medium">Education</h2>
<div class="text-button-container flex-col">
<h2 class="font-sans text-[54px] font-medium">Living Situation</h2>
<div
class="scroll-container max-w-[574px] max-h-[210px] overflow-auto"
class="scroll-container max-w-[574px] max-h-[210px] overflow-auto" id="scroll-container-lisi"
>
<p class="scroll-content font-sans text-lg">
Many of the children we enroll as students in MMF live on the
Expand All @@ -495,13 +497,13 @@ <h2 class="font-sans text-[54px] font-medium">Living Situation</h2>
</p>
</div>
<div class="button-container flex justify-between items-start mt-10">
<button class="reg-button bg-black text-white">READ MORE</button>
<button class="reg-button bg-black text-white" id="read-more-btn-lisi">READ MORE</button>
<button class="reg-button bg-[#EE6352] text-white">DONATE</button>
</div>
</div>
</div>
<div
class="flex flex-row-reverse justify-center items-center w-full h-[576px] gap-8 my-8"
class="flex flex-row-reverse justify-center items-center w-full h-[576px] gap-8 my-8" id="section-container-food"
>
<div class="max-w-[574px] max-h-[576px] overflow-hidden">
<img
Expand All @@ -514,7 +516,7 @@ <h2 class="font-sans text-[54px] font-medium">Living Situation</h2>
<div class="text-button-container flex-col">
<h2 class="font-sans text-[54px] font-medium">Food Distribution</h2>
<div
class="scroll-container max-w-[574px] max-h-[210px] overflow-auto"
class="scroll-container max-w-[574px] max-h-[210px] overflow-auto" id="scroll-container-food"
>
<p class="scroll-content font-sans text-lg">
Despite Madagascar being known for its lush climate, the country
Expand All @@ -529,12 +531,12 @@ <h2 class="font-sans text-[54px] font-medium">Food Distribution</h2>
</p>
</div>
<div class="button-container flex justify-between items-start mt-10">
<button class="reg-button bg-black text-white">READ MORE</button>
<button class="reg-button bg-black text-white" id="read-more-btn-food">READ MORE</button>
<button class="reg-button bg-[#EE6352] text-white">DONATE</button>
</div>
</div>
</div>
<div class="flex justify-center items-center w-full h-[576px] gap-8 my-8">
<div class="flex justify-center items-center w-full h-[576px] gap-8 my-8" id="section-container-music">
<div class="max-w-[574px] max-h-[576px] overflow-hidden">
<img
class="object-cover h-[576px]"
Expand All @@ -546,7 +548,7 @@ <h2 class="font-sans text-[54px] font-medium">Food Distribution</h2>
<div class="text-button-container flex-col">
<h2 class="font-sans text-[54px] font-medium">Music Lessons</h2>
<div
class="scroll-container max-w-[574px] max-h-[210px] overflow-auto"
class="scroll-container max-w-[574px] max-h-[210px] overflow-auto" id="scroll-container-music"
>
<p class="scroll-content font-sans text-lg">
Meeting basic needs is crucial, but we also recognize that
Expand Down Expand Up @@ -580,13 +582,13 @@ <h2 class="font-sans text-[54px] font-medium">Music Lessons</h2>
</p>
</div>
<div class="button-container flex justify-between items-start mt-10">
<button class="reg-button bg-black text-white">READ MORE</button>
<button class="reg-button bg-black text-white" id="read-more-btn-music">READ MORE</button>
<button class="reg-button bg-[#EE6352] text-white">DONATE</button>
</div>
</div>
</div>
<div
class="flex flex-row-reverse justify-center items-center w-full h-[576px] gap-8 my-8"
class="flex flex-row-reverse justify-center items-center w-full h-[576px] gap-8 my-8" id="section-container-futuregoals"
>
<div class="max-w-[574px] max-h-[576px] overflow-hidden">
<img
Expand All @@ -599,7 +601,7 @@ <h2 class="font-sans text-[54px] font-medium">Music Lessons</h2>
<div class="text-button-container flex-col">
<h2 class="font-sans text-[54px] font-medium">Future Goals</h2>
<div
class="scroll-container max-w-[574px] max-h-[210px] overflow-auto"
class="scroll-container max-w-[574px] max-h-[210px] overflow-auto" id="scroll-container-futuregoals"
>
<p class="scroll-content font-sans text-lg">
One of our goals is to make MMF larger and more well-known so that
Expand Down Expand Up @@ -644,12 +646,12 @@ <h2 class="font-sans text-[54px] font-medium">Future Goals</h2>
</p>
</div>
<div class="button-container flex justify-between items-start mt-10">
<button class="reg-button bg-black text-white">READ MORE</button>
<button class="reg-button bg-black text-white" id="read-more-btn-futuregoals">READ MORE</button>
<button class="reg-button bg-[#EE6352] text-white">DONATE</button>
</div>
</div>
</div>
<div class="flex justify-center items-center w-full h-[576px] gap-8 my-8">
<div class="flex justify-center items-center w-full h-[576px] gap-8 my-8" id="section-container-activities">
<div class="max-w-[574px] max-h-[576px] overflow-hidden">
<img
src="/assets/placeholder-images/IMG_3538.webp"
Expand All @@ -660,7 +662,7 @@ <h2 class="font-sans text-[54px] font-medium">Future Goals</h2>
<div class="text-button-container flex-col">
<h2 class="font-sans text-[54px] font-medium">Activities</h2>
<div
class="scroll-container max-w-[574px] max-h-[210px] overflow-auto"
class="scroll-container max-w-[574px] max-h-[210px] overflow-auto" id="scroll-container-activities"
>
<p class="scroll-content font-sans text-lg">
Children growing up in poverty in Antsirabe often have significant
Expand Down Expand Up @@ -699,7 +701,7 @@ <h2 class="font-sans text-[54px] font-medium">Activities</h2>
</p>
</div>
<div class="button-container flex justify-between items-start mt-10">
<button class="reg-button bg-black text-white">READ MORE</button>
<button class="reg-button bg-black text-white" id="read-more-btn-activities">READ MORE</button>
<button class="reg-button bg-[#EE6352] text-white">DONATE</button>
</div>
</div>
Expand Down

0 comments on commit f4d1aa0

Please sign in to comment.