Some test text!
Web / Guides / Hide/Show DOM elements
Hiding DOM elements is an essential aspect of a customizable UI. WebViewer UI supports hiding/showing elements both initially and dynamically.
To hide/show the DOM elements, first you must find the data-element
attribute on the elements from a DOM inspector. For example, if we inspect the left panel,
we can find that it has a data-element
value of leftPanel
. Now we can use that value to hide/show it.
To hide the DOM elements even before the initial render, you can use a constructor option disabledElements
to pass a list of data-element
values that should be hidden.
Example
const wvElement = document.getElementById('viewer');
WebViewer({
path: 'lib',
disabledElements: [
'viewControlsButton',
'viewControlsOverlay'
]
}, wvElement);
To enable/disable the DOM elements, you can use the following APIs:
Example
const wvElement = document.getElementById('viewer');
WebViewer({ ...options }, wvElement).then(() => {
// remove left panel and left panel button from the DOM
instance.UI.disableElements([ 'leftPanel', 'leftPanelButton' ]);
// re-enable left panel and left panel button from the DOM
instance.UI.enableElements([ 'leftPanel', 'leftPanelButton' ]);
});
Note that these are different from opening/closing elements. Instead of changing visibility, these APIs will actually remove/re-render elements in the DOM. To change visibility, you can refer to the sample below.
You can toggle panels, overlays, popups, and modals.
Example
const wvElement = document.getElementById('viewer');
WebViewer({ ...options }, wvElement).then(() => {
// opens (shows) text popup and annotation popup in the UI
instance.UI.openElements([ 'menuOverlay', 'leftPanel' ]);
// closes (hides) text popup and left panel in the UI
instance.UI.closeElements([ 'menuOverlay', 'leftPanel' ]);
});
Trial setup questions? Ask experts on Discord
Need other help? Contact Support
Pricing or product questions? Contact Sales