Error "Error: Offcanvas Element not found" when Off Canvas not present
guyhamilton opened this issue · 3 comments
guyhamilton commented
Hi everyone,
First of all great plugin - work's so well and is easily customisable.
I have a site that uses the off canvas menu on some pages and not on others. This is moreso a question for anyone else that has experienced it,
- but when a page loads without an off canvas menu present it throws a 'Error: Offcanvas Element not found'. Thats understandable, but I'm just wondering whether anyone has found a way to initialise only if there is a off canvas on the page to stop this error? I have tried to do this using the below code but no luck.
I know this isn't a problem with the menu, its more about implementation - but I figured someone might have found a solution so I thought I would ask. Again, awesome plugin!
var
if ($ocRight.length) {
$('#off-canvas-right').offcanvas({
modifiers: "right,overlay",
triggerButton: '.js-offcanvas-trigger'
});
}
vmitsaras commented
Hi @guyhamilton,
check for the Button instead for the Menu.
Try this:
<!-- Page with Offcanavs-->
<a href="#offCanvas" id="triggerButton">Menu</a>
<aside id="offCanvas">...</aside>
<!-- Page without Offcanavs-->
<aside id="offCanvas">...</aside>
var $triggerButton= $('#triggerButton');
if ($triggerButton.length) {
$('#offCanvas').offcanvas({
modifiers: "left,overlay",
triggerButton: '#triggerButton'
});
}
vmitsaras commented
Hi @guyhamilton,
is this still relevant to you?
guyhamilton commented
Hi, sorry no that worked a treat thank you!!!
…On Wed, 16 Oct 2019 at 4:50 am, Vasileios Mitsaras ***@***.***> wrote:
Hi @guyhamilton <https://github.com/guyhamilton>,
is this still relevant to you?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#45?email_source=notifications&email_token=AAIWKQANT3IETZCFQBNO2OTQO3PVPA5CNFSM4IJF7NP2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBL4IFQ#issuecomment-542622742>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIWKQHT42RMNHTXSNNGXZ3QO3PVPANCNFSM4IJF7NPQ>
.