Displays an overlay when a section moves out of the viewport.
Add the wb-inview class to an element.
<section class="wb-inview">
...
</section>
Handle the view state changes using one of the following approaches:
Overlays: You can open and close overlays based upon an element's view state.
data-inview attribute to the element with the value being the unique id of the overlay added in the previous step.show-none class to the element to make the overlay only open when the element is fully out of view (default is partially out of view).Show/hide content: You can show/hide content with CSS transitions, based upon an element's view state.
fade, slide, slidevert, etc.)reverse class with the CSS transition.data-inview attribute to the element with the wb-inview class with the value being the unique id of the element with the CSS transition class.show-none class to the wb-inview element, the CSS transition only occur when the wb-inview element is:
Events: You can handle the view state change events through JavaScript.
Add an event handler to listen for each of the view state changes:
$( document ).trigger( "all.wb-inview partial.wb-inview none.wb-inview", function( event ) {
if ( event.namespace === "wb-inview" ) {
switch ( eventType ) {
case "all":
// event.target is a wb-inview element that has become completely visible
break;
case "partial": {
// event.target is a wb-inview element that has become partially hidden
break;
case "none":
// event.target is a wb-inview element that has become completely hidden
}
}
});
The view state of this section is being identified below through JavaScript.
View state:
<section class="wb-inview bar-demo">
<h3 class="no-gutter">View state change events</h3>
...
</section>
(function( $, wb ) {
"use strict";
wb.doc.on( "all.wb-inview partial.wb-inview none.wb-inview", function( event) {
if ( event.namespace === "wb-inview" ) {
$( event.target ).find( ".view-state-status" ).html( event.type );
}
});
})( jQuery, wb );
| Option | Description | How to configure | Values |
|---|---|---|---|
data-inview |
Identifies the element to trigger a change on (uses the unique id of the element). | Add the data-inview attribute with the value being the unique id of the element to trigger a change on. |
Unique id of the target element |
show-none |
Overrides the overlay/CSS transition trigger to only occur when:
|
Add the show-none class to the element. |
n/a |
| Event | Trigger | What it does |
|---|---|---|
wb-init.wb-inview |
Triggered manually (e.g., $( ".wb-inview" ).trigger( "wb-init.wb-inview" );). |
Used to manually initialize the Data Inview plugin. Note: The Data Inview plugin will be initialized automatically unless the required markup is added after the page has already loaded. |
wb-ready.wb-inview (v4.0.5+) |
Triggered automatically after the Data InView plugin has initialized. | Used to identify where the Data InView plugin was initialized (target of the event)
|
all.wb-inview (v4.0.4+) |
Triggered automatically when a wb-inview element becomes completely visible. |
Used to identify that the view state of a wb-inview element has changed to all.
|
partial.wb-inview (v4.0.4+) |
Triggered automatically when a wb-inview element becomes partially hidden. |
Used to identify that the view state of a wb-inview element has changed to partial.
|
none.wb-inview (v4.0.4+) |
Triggered automatically when a wb-inview element becomes completely hidden. |
Used to identify that the view state of a wb-inview element has changed to none.
|
wb-ready.wb (v4.0.5+) |
Triggered automatically when WET has finished loading and executing. | Used to identify when all WET plugins and polyfills have finished loading and executing.
|