ScrollShow is a JavaScript library to make DOM elements "scroll to show".
For example, if we want DOM elements to stay hidden initially and only becomes visible when user scrolls them into viewport.
Add the following script into the HTML file
<script src="https://cdn.jsdelivr.net/gh/iamfranco/[email protected]/scrollShow.js"></script>Add a CSS rule for .scrollShow so that those elements are initially hidden.
Add a CSS rule for .scrollShow.show so that those elements can be visible later.
.scrollShow {
opacity: 0; /* hidden */
transition: 0.2s ease all;
}
.scrollShow.show {
opacity: 1; /* now visible */
}For DOM elements that you want to "scroll to show", add a scrollShow class to them
<div class="[some class...] scrollShow">
[some content ...]
</div>After the closing body tag, add the JavaScript
scrollShow.addItems()so that all those DOM elements with the scrollShow class are tracked.
Now, whenever a tracked element gets scrolled "into view", the element will have the show class automatically added to it, which makes the element visible.
There are more data- options that you can specify in an element for more fine tuned scrollShow behaviour
<div class="scrollShow"
data-scroll-show-class="show"
data-scroll-show-element-percent="100"
data-scroll-show-viewport-percent="0">
[...]
</div>-
data-scroll-show-classis the class name to be added to the element when it is "in view".
By default, that's theshowclass. -
data-scroll-show-element-percentis how much an element (measuring from the top, in percentage of height) should be visible, in order for it to be considered "in view".
By default, that's100%, i.e. right at the bottom of the element. -
data-scroll-show-viewport-percentis where the "in view threshold" is located at within the viewport (measuring from the bottom, in percentage of height).
By default, that's0%, i.e. right at the bottom of the viewport.
There are some properties within the scrollShow object that controls how scrollShow behaves
scrollShow.delay = 0.05 // time delay (seconds)
scrollShow.default_element_percent = 100 // percent of element height
scrollShow.default_viewport_percent = 0 // percent of viewport height
scrollShow.hide_on_scroll_back = false // hide elements when we scroll back?.delayis the time (in seconds) it takes between consecutive elements become visible, so that they can appear "sequentially" as opposite to "suddenly all appearing at the same time"..default_element_percentis the default value for thedata-scroll-show-element-percentattribute..default_viewport_percentis the default value for thedata-scroll-show-viewport-percentattribute..hide_on_scroll_backis boolean for if we want elements to hide when we scroll back up.