Unverified

Name

Off-Canvas-Widget-Anchors

About

Ensure the New Off Canvas Widget closes when you click on a Same Page Menu Anchor

Language

HTML

Rating

Voted: 1 by 1 user(s)

How to Setup Snippet

Add this into the Off Canvas Widget Container as HTML. Ensure the Icon/Toggle that opens the Off Canvas has the class name: 'off-canvas-toggle-button'

Codevault

WebSquadron

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.4

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

20/06/2024

Important Note

This snippet has the following status:

Unverified

This snippet has not been verified, use with caution and at your own risk. See details provided by author in sidebar and click below to find out more.

Off-Canvas-Widget-Anchors

 
                    
1<style>
2/* Keyframes for slide-in and slide-out animations */
3@keyframes slideInLeft {
4 from {
5 transform: translateX(-100%);
6 }
7 to {
8 transform: translateX(0);
9 }
10}
11 
12@keyframes slideOutLeft {
13 from {
14 transform: translateX(0);
15 }
16 to {
17 transform: translateX(-100%);
18 }
19}
20 
21/* Custom styles to manage Off Canvas visibility */
22.e-off-canvas-hidden {
23 animation: slideOutLeft 1s forwards; /* Adjusted duration */
24}
25 
26.e-off-canvas-visible {
27 animation: slideInLeft 0.5s forwards;
28}
29 
30.e-off-canvas-overlay-hidden {
31 display: none !important;
32}
33</style>
34<script>
35jQuery(function($){
36 // Function to hide the Off Canvas and overlay
37 function hideOffCanvas() {
38 $('[class^="e-off-canvas"]').removeClass('e-off-canvas-visible').addClass('e-off-canvas-hidden');
39 $('.e-off-canvas__overlay').addClass('e-off-canvas-overlay-hidden');
40 $('body').removeClass('e-off-canvas__no-scroll');
41 }
42 
43 // Function to show the Off Canvas and overlay
44 function showOffCanvas() {
45 $('[class^="e-off-canvas"]').removeClass('e-off-canvas-hidden').addClass('e-off-canvas-visible');
46 $('.e-off-canvas__overlay').removeClass('e-off-canvas-overlay-hidden');
47 $('body').addClass('e-off-canvas__no-scroll');
48 }
49 
50 // Handle link clicks inside the Off Canvas
51 $(document).on('click', '[class^="e-off-canvas"] a', function(event){
52 var target = $(this).attr("href");
53 
54 // Check if the link is an action to close the Off Canvas
55 if (target.includes('elementor-action%3Aaction%3Doff_canvas%3Aclose')) {
56 event.preventDefault();
57 hideOffCanvas();
58 return;
59 }
60 
61 var split_url = target.split('#');
62 
63 // Check if the link is an anchor link within the same page
64 if (split_url.length > 1 && (window.location.pathname == split_url[0] || split_url[0] == '')){
65 event.preventDefault();
66 $('html, body').animate({
67 scrollTop: $('#'+split_url[1]).offset().top
68 }, 1000);
69 hideOffCanvas();
70 } else {
71 hideOffCanvas();
72 }
73 });
74 
75 // Handle the Off Canvas toggle button click
76 $(document).on('click', '.off-canvas-toggle-button', function(event){
77 showOffCanvas(); // Show the Off Canvas and overlay
78 });
79});
80</script>

1

Related Snippets

Please see some snippets below related to this snippet..

Elementor

Public

3

Align Icon List items to the top

Added: 1 year ago

Last Updated: 1 year ago

Align Icon List widget items to the top, instead of the middle

Elementor

AI Verified

0

Elementor author posts with UAE Posts widget

Added: 1 year ago

Last Updated: 1 year ago

Display posts of only the current author archive using Elementor and "Unlimited Addons for Elementor" Posts widget

Elementor

AI Verified

0

Custom Class for Elementor Form Widget Items

Added: 5 months ago

Last Updated: 5 months ago

Add custom classess to form elements using elementor; Note: if you want to add to other field types like select, then just add this to the allowed fields array: $allowed_fields just add the type, lik...

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

Performance

AI Verified

31

Remove Unused Javascript

Added: 1 year ago

Last Updated: 1 month ago

Remove Unused Javascript - and improve your Page Speed Insight Score

WooCommerce

Pro Verified

10

Deactivate some WooCommerce Checkout Fields

Added: 1 year ago

Last Updated: 1 week ago

Deactivate some WooCommerce Checkout Fields from showing

Elementor

AI Verified

6

CSS Grid Aid

Added: 7 months ago

Last Updated: 1 month ago

This can be used for any WordPress Builder to aid working with CSS Grids.