Hi there,
Sir, Visible in viewport.
Currently, this below controls the viewport →
.slider {
display: flex;
gap: 5%;
justify-content: space-between;
overflow: hidden;
}
article.commonclass {
flex: 0 0 30%;
margin: 70px auto;
}
In browser, it appears like this →
section: 9 article
viewport: 3 article
visible in viewport
Now, let us say that at some other viewport width we change css:
.slider {
display: flex;
gap: 10%;
justify-content: space-between;
overflow: hidden;
}
article.commonclass {
flex: 0 0 45%;
margin: 70px auto;
}
45% + 45% + 10%(gap property) = 100% viewport width = Two elements visible in viewport
section: 9 article
viewport: 2 article
visible in viewport
Furthermore at some other width of viewport or media query:
.slider {
display: flex;
justify-content: space-between;
overflow: hidden;
}
article.commonclass {
flex: 0 0 100%;
margin: 70px auto;
}
section: 9 article
viewport: 1 article
visible in viewport
In real life situation in full viewport width, there can be 4, and in other lesser viewport widths, there can be 3, 2, or 1
article
visible in the viewport.
I have most of the things clear, but two challenges:
#1 →
In some var sectionArticleViewport = {some javascript code that will fetch total number of visible article in the viewport within that section}
#2 → I had a discussion with you on another post, which has a for next click like this →
const nextClick = document.querySelector(".next");
nextClick.addEventListener('click', event => {
console.log("Yes Next Event Triggered");
event.preventDefault();
var noHoliday = document.querySelector("article.commonclass:not(.holidayclass)") && document.querySelector("article.commonclass:not(.holidayclass2)");
var nSibling = noHoliday.nextElementSibling;
if (nSibling.classList.contains("holidayclass")) {
nSibling.classList.remove("holidayclass");
noHoliday.classList.add("holidayclass2");
currentIndex = currentIndex + 1;
document.querySelector(".currentslide").innerHTML = currentIndex;
}
});
The second challenge is currently I am working on just nextElementSibling
, →
nSibling.classList.remove("holidayclass");
noHoliday.classList.add("holidayclass2");
but later once I have this variable → var sectionArticleViewport
based on that numeric I have to update classes in the next 3, 2, or 1 sibling based on the number of articles in the viewport that will be captured in → var sectionArticleViewport
Matchmedia concept is new to me let me have a look.