Webflow sync, pageviews & more.
NEW

Escape Close Modal Accessibility

Example

Escape Close Modal Accessibility

Description

Add accessibility functionality to your Webflow modals with this Javascript code. When a user presses escape the modal window will automatically close.

Instructions

  1. Review the sample HTML structure and elements for familiarity
  2. Add the custom JS code to the closing body tag of your custom code page settings
  3. The button to open and close must be an immediate sibling below modal-wrapper
  4. The button that opens the modal must have a custom attribute of modal="button"

Javascript snippet


<script>
$(document).ready(function () {
    var findDialog = function (elem) {

        var tabbable = elem.find('select, input, textarea, button, a').filter(':visible');

        var firstTabbable = tabbable.first();
        var lastTabbable = tabbable.last();
        /*set focus on first input*/
        firstTabbable.focus();

        /*redirect last tab to first input*/
        lastTabbable.on('keydown', function (e) {
            if ((e.which === 9 && !e.shiftKey)) {
                e.preventDefault();
                firstTabbable.focus();
            }
        });

        /*redirect first shift+tab to last input*/
        firstTabbable.on('keydown', function (e) {
            if ((e.which === 9 && e.shiftKey)) {
                e.preventDefault();
                lastTabbable.focus();
            }
        });


        /* allow escape key to close insiders div */
        elem.on('keyup', function (e) {
            if (e.keyCode === 27) {
                document.querySelector('.modal-close_btn').click();
            };
        });


    };


    $('[modal=button]').click(function (e) {
        e.preventDefault();

        $(this).next().show();
        findDialog($(this).next());
    });

    $('.modal-close_btn, .modal-close_area').click(function (e) {
        e.preventDefault();

        $('.modal-wrapper').hide();
    });


});
</script>

CSS snippet

HTML snippet


<a modal="button" class="button cc-primary">Open Modal</a>
<div class="modal-wrapper" role="dialog" aria-modal="true" aria-labelledby="Popup Modal">
    <div class="modal-container">
        <div class="p-2">
            <h3>This is a modal</h3>
            <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</p>
            <a href="#" class="button cc-primary">Button</a>
            <a href="#" class="modal-close_btn">
                <span class="sr-only">Close Modal</span>
                <span aria-hidden="true">×</span>
            </a>
        </div>
    </div>
    <div tabindex="-1" aria-hidden="true" class="modal-close_area"></div>
</div>
Draggable Text Area Input Resizing

Draggable Text Area Input Resizing

2

Make your default form inputs draggable and resizable on your Webflow sites with this CSS snippet. This CSS snippet allows for you to make your default form field inputs resizable by your users/visitors on your Webflow sites.

Swipe Webflow Tabs

Swipe Webflow Tabs

Add native swiping gestures to Webflow tabs to allow for swiping between tabs with this Javascript code. Webflow doesn't natively support swiping gestures, however it's easy to add swiping gestures to switch between tabs via this JS code.

Navigate Webflow Slider with Arrow Keys

Navigate Webflow Slider with Arrow Keys

Add arrow keys keyboard functionality to Webflow's native slider with this simple Javascript code. This added functionality allows users to use their keyboards to navigation through slides in a Webflow slider.

Skip Link Accessibility

Skip Link Accessibility

Add accessibility features to your Webflow site by allowing to skip links with the keyboard only. Skip links allows keyboard navigation or screen readers to jump past the site navigation quickly. This allows for better accessibility for your Webflow sites.

Reduced motion media query

Reduced motion media query

The ability to hide and show elements on your Webflow site based on if a user has reduced motion activated in their operating system. Adding this Javascript code helps with accessibility by hiding and showing elements based on the users predefined OS accessibility settings.

Keyboard Accessibility Slider Arrows

Keyboard Accessibility Slider Arrows

Add keyboard accessibility functionality to your Webflow site with this custom Javascript code. This allows users to navigate between slides using their keyboards offering better accessibility to your Webflow sites.

Prefer Reduced Motion on Anchors

Prefer Reduced Motion on Anchors

This allows you to utilize users OS preferences for reduced motion on anchors in Webflow. Adding this Javascript code snippet to your page settings helps the accessibility of your Webflow site based on your users preferences.

DRAG
Real-time sorting by
Hide/show Items based on URL Parameter

Hide/show Items based on URL Parameter

Show or hide divs or elements based on the parameter within a URL in Webflow. This Javascript code allows you to make your Webflow site even more dynamic by allowing you to customize elements on the page based on the URL parameter provided.

Reload Page after Form Submit

Reload Page after Form Submit

Automatically refresh your Webflow site's page after a form submit with this Javascript snippet. A great way of indicating that a form has been submitted to a user or refreshing the page for another submission.

Count Up Numbers on Page Scroll

Count Up Numbers on Page Scroll

When scrolling down the page numbers count up as they enter browser view via this Javascript snippet on your Webflow site. An easy way to add number count up to your Webflow site.

SVG Clip-path for Custom Image Cropping

SVG Clip-path for Custom Image Cropping

Create a responsive clip path for images using SVG shapes in Webflow.This allows you to create unique shaped images using SVG paths rather than DIVs or similar methods.

Prevent Input Zoom Scaling on Mobile

Prevent Input Zoom Scaling on Mobile

Prevent an input form zoom scaling on mobile on your Webflow site. This allows for a better user experience based on your sites design rather than mobile OS zoom default properties.

International Flags Phone Number Input

International Flags Phone Number Input

Add international flags to a phone number for input in Webflow. Adding this allows for a unique way of adding international flags to a phone form field in your Webflow site.

Infinite CSS Marquee/Ticker Logo

Infinite CSS Marquee/Ticker Logo

An easy way to utilize CSS for Logo marquees and other sections in your Webflow site. An easier way to create an infinite looping marquee on your Webflow site than creating them manually with Webflow interactions.

Truncate multi-line text with Ellipse

Truncate multi-line text with Ellipse

Do you want consistency with your Webflow designs? Truncate multi-line texts with ellipses based on 2 or 3 lines of your choosing via CSS. This helps keep your designs uniformed without needing to set max height limitations by truncating text that goes beyond a certain length.

DRAG
Real-time sorting by