There is a similar thread found here : Link to off-canvas content from 2017. But I thought I’d contribute to the conversation in case anyone needs to do this and experienced the same trouble I ran into using 6.1.9.
The Problem:
Before I solved it, the trouble was that the replaced Toggle I made from a div with a Raw Content element containing a custom SVG was not triggering the Off Canvas element while using the code found in the post from 2017. It was only getting as far as animating the default Toggle hamburger, which would then just return to its default state and no Off Canvas would slide out.
The solution:
Wrap the reference to the original Toggle in the jQuery in a short timeout like this:
jQuery(function(){
jQuery(’#custom-trigger’).click(function(e) {
e.preventDefault();
setTimeout(() => {
jQuery(’#default-target-anchor-toggle’).click();
}, 100);
})
});
And here’s a little bit of CSS to support the effort:
#default-target-anchor-toggle { display:none; }
.tco-preview #default-target-anchor-toggle {
display:initial;
border-radius:5px;
border:1px dashed rgb(0 0 0 / 0.2);
}
This hides the default Toggle on the front end but makes it visible in the builder so you can continue to trigger the Off Canvas element in there and work on its content (the replacement Toggle wont trigger it in the builder).
Change your ID’s as you see fit or use classnames if you want. Use your dev tools to figure what you wanna target and create what you want to replace that with.
Questions for Support:
This jQuery gets the job done as far as I can tell. But why did the code from 2017 need to have the timeout added as I have done? Did something change about the way this works since then that we need to be aware of?
Thanks!