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/scrollShow@v1.0.0/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-class
is the class name to be added to the element when it is "in view".
By default, that's theshow
class. -
data-scroll-show-element-percent
is 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-percent
is 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?
.delay
is 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_percent
is the default value for thedata-scroll-show-element-percent
attribute..default_viewport_percent
is the default value for thedata-scroll-show-viewport-percent
attribute..hide_on_scroll_back
is boolean for if we want elements to hide when we scroll back up.