Data Inview
Purpose
Displays an overlay when a section moves out of the viewport.
Working example
Issues and Testing
How to implement
-
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.
- Add an overlay with a unique id. See the overlay documentation for further details.
- Add the
data-inview
attribute to the element with the value being the unique id of the overlay added in the previous step. - Optional: Add the
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.
- Add an element with a unique id.
- Add a CSS transition class to the element added in the previous step (e.g.,
fade
,slide
,slidevert
, etc.) - Optional: Reverse the transition by adding the
reverse
class with the CSS transition. - Add the
data-inview
attribute to the element with thewb-inview
class with the value being the unique id of the element with the CSS transition class. - Optional: Add the
show-none
class to thewb-inview
element, the CSS transition only occur when thewb-inview
element is:- located Before and fully out of view (default is partially out of view)
- located After and partially out of view (default is fully out of view)
-
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 } } });
-
-
View state change events
The view state of this section is being identified below through JavaScript.
View state:
HTML
<section class="wb-inview bar-demo">
<h3 class="no-gutter">View state change events</h3>
...
</section>
JavaScript
(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 );
Configuration options
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 |
in-only |
Displays the transition, the section that is triggered will then stay in place | Add the in-only class to the element. |
n/a |
Events
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.
|
Source code
- Date modified: