Unable to close Bootstrap sidebar menu on mobile devices

I implemented a sidebar menu for mobile that opens when you click on the hamburger icon, with a dark overlay covering the body. The issue I encountered is that on mobile devices, the visibility of the menu does not change when clicked outside of it. It works perfectly fine on desktop and newer devices like iPhone 10, but on testing with iPhone 8 and older models, the mobile menus remain active. Below is the code snippet; I believe I may have overlooked some CSS properties.

Here is an excerpt from the sidebar snippet used in the theme.liquid file:

<body id="{{ page_title | handle }} menu" class="template-{{ template.name | handle }}">
  <div id="whileyApp" class="whiley-theme"></div>

  <div id="aside_main" class="sidebar-menu">
    {%- include 'sidebar-menu' -%}
  </div>
</body>

This is the toggle button for the hamburger menu:

<div class="toggle">
   <a href="#" class="burger js-menu-toggle-home" data-toggle="collapse" data-target="#main-navbar">
     <span></span>
   </a>
</div>

And here's the HTML markup within the sidebar-menu snippet:

  <div class="side-inner">
    <div class="profile">
      <a href="{{shop.url}}" title="{{ shop.name | escape }}">
        {%- assign mobile_logo = "logo.png" | asset_img_url: 'master'  -%}
        {%- if settings.main_logo != blank -%}
        {%- assign mobile_logo = settings.main_logo | img_url: 'master' -%}
        {%- endif -%}
        <img src="{{ mobile_logo }}"{{' '}}{%-if settings.mobile_logo_max_width != blank -%}style="max-width:{{settings.mobile_logo_max_width}}px;"{%-endif-%}{{' '}}title="{{ shop.name | escape }}" alt="{{ shop.name | escape }}" class="img-fluid"/>
      </a>
    </div>

    {% for link in linklists[settings.mobile_linklist].links %}
    {% if link.links != blank %}
      <div class="nav-menu">
        <ul id="accordion">
          <li class="accordion">
            <span><a aria-controls="collapseOne"
               aria-expanded="false"
               class="collapsible"
               data-target="#collapse{{forloop.index}}"
               data-toggle="collapse"
               href="#">{{ link.title }}
             </a></span>

            <div aria-labelledby="headingOne" class="collapse" id="collapse{{forloop.index}}">
                <ul>
                  {% for childlink in link.links %}
                  <li>
                    <a href="{{childlink.url}}">{{childlink.title}}</a>
                  </li>
                  {% endfor %}
                </ul>
            </div>
          </li>
        </ul>
      </div>
    {% endif %}
    {% endfor %}
    <div class="nav-menu">
      <ul id="static-pages">
      <li class="accordion"><a href="/account">
        {%- if customer -%}
        Hi, {{ customer.first_name }}
        {%- else -%}{{ 'customer.account.title' | t }}</a></li>
        {% endif %}
      </ul>
    </div>
  </div>

The CSS provided below works well for desktop sites, but encounters issues on mobile Safari or Chrome IOS versions below 8:

#aside_main {
    /* CSS code here */
}

/* More CSS styles... */

body.show-sidebar-main:before {
  /* CSS code here */
}

And here is the JavaScript code responsible for controlling classes:

//Mobile menu
$(function() {

  'use strict';

  $('.js-menu-toggle-home').click(function(e) {
    // JS code for toggling menu
  });

  // Clicking outside offcanvas
    $(document).mouseup(function(e) {
    // JS code for handling click outside behavior
    });

});

Answer №1

Recently, I updated the $(document).mouseup(function(e) { } to $(document).bind("mouseup touchend", function(e) {} and it appears to be functioning properly now.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to determine the final letter of a column in a Google Sheet, starting from the first letter and using a set of

My current approach involves generating a single letter, but my code breaks if there is a large amount of data and it exceeds column Z. Here is the working code that will produce a, d: const countData = [1, 2, 3, 4].length; const initialLetter = 'A&a ...

What is the best way to make background SVGs tile seamlessly within the cells of a table?

I am currently dealing with a series of table cells that are filled with various colors and styles. The issue I'm facing is getting the styles to tile properly, as they are not seamlessly continuing from one cell to the next even if they share the sam ...

Pattern to identify a JSON string with Regular Expressions

Currently, I am working on developing a JSON validator from the ground up and have hit a roadblock when it comes to the string component. My original plan was to create a regex pattern that aligns with the sequence specified on JSON.org: Here is the regex ...

Issues arising with the functionality of CSS media queries when used in conjunction with the

I created a webpage that is functioning well and responsive on its own. However, when I integrate the same files with the Spring framework, the responsiveness of the webpage seems to be lost. To ensure the responsiveness of the Spring webpage, I tested it ...

HTML5 input placeholder adapts its size and position dynamically as data is being

During my interaction with the input fields on my bank's website, I noticed that the placeholder text undergoes a unique transformation. It shrinks in size and moves to the upper-left corner of the input field while I am entering information. Unlike t ...

Exploring jQuery Efficiency: Comparing CSS and Animation Techniques

I am trying to steer clear of using the animation property because it tends to be slower compared to CSS3 animations. My query is whether utilizing the css method is faster than the animation property, but still slower than a direct CSS3 animation with tr ...

Functionalities of HTML controls

I currently have a select element in my HTML code which looks like this: <select> <option id="US" value="US"> </option> <option id="Canada" value="Canada"> </option> </select> My requirements are twofold: ...

Interacting with touch events in JavaScript on Android devices

I am facing an issue with my HTML page where a div is meant to function as an on-off switch momentarily. The functionality I have implemented looks like this: $('#btn').mousedown(function() { startAction() }) $('#btn ...

Steps for deleting a game objectWould you like to learn how to

What is the process of creating an object that can eliminate itself automatically? var item = []; function selfDestruct() { this.destroy = () => { this = false; } } function initialization() { item[0] = new SelfDestruct(); item[0].destroy( ...

Error encountered in Intellij for Typescript interface: SyntaxError - Unexpected identifier

I am currently testing a basic interface with the following code: interface TestInterface { id: number; text: string; } const testInterfaceImplementation: TestInterface = { id: 1, text: 'sample text' }; console.log(testInterface ...

Issue: Unable to set headers after they have been sent while using express-fileupload in the application

app.post('/profile', function(req, res) { // save file if (req.files) { let sampleFile = req.files.sampleFile; sampleFile.mv('/somewhere/on/your/server/filename.jpg', function(err) { if (err) ...

Using jQuery within MediaWiki pages beyond just Monobook.js or extensions is a powerful tool

Currently, I am experimenting with some jQuery functionalities in a MediaWiki content page to enhance various features. I have referred to the following resources: http://www.mediawiki.org/wiki/Manual:$wgRawHtml (particularly for incorporating Paypal but ...

When running scripts, Protractor is unable to perform a click action in Safari, even though it works perfectly in

Currently, I am in the process of developing an angular application and utilizing directconnect for Chrome and Firefox. All my test scripts are functioning as expected, however, a new requirement has been introduced to run these same tests on Safari. To ...

Create a custom hook that encapsulates the useQuery function from tRPC and provides accurate TypeScript typings

I have integrated tRPC into a project that already has API calls, and I am looking to create a separate wrapper for the useQuery function. However, I am facing challenges in getting the TypeScript types right for this customization. My Objective This is w ...

Menu becomes sticky too quickly on iOS Safari and Chrome, jumping to fixed position prematurely

Feeling frustrated with this seemingly straightforward code challenge. My sticky menu is causing me headaches on iOS devices, particularly the iPhone 6 running the latest iOS. It seems like the menu jumps into its fixed position too early, leading me to be ...

What steps can I take in JavaScript to assign a value of 0 to values[1] in order to prevent receiving NaN as the output

I'm currently working on a program that calculates the sum of 6 input values, but I've encountered an issue where if a value is missing (for example, only providing 5 values), the result becomes NaN. I attempted to address this by assigning empty ...

Ways to eliminate the blue selection box when dragging canvas objects in fabric framework

I've been trying to find a solution to remove the annoying blue highlight box that appears when dragging on the canvas while using fabric js, but so far I haven't had any luck. I've tried the following code, but it only works for text and n ...

What is the purpose of encasing the routes within the <Switch> element in react-router, when they seem to function perfectly fine without it

Currently utilizing react-router-dom version 5.2.0. As a practice, I typically enclose all my Route components within a Switch component. For instance: const MyRoutes = () => ( <Switch> <Route path='/route1' exact ...

Button inside table cell not showing Bootstrap tooltip

I've implemented a feature where each row in a table has a button that triggers a pop-up modal when clicked. I want these buttons to display tooltips when hovered over and when focused. Below is an example of the HTML structure: <link hr ...

Error: React Component not rendering correctly - Element Type Invalid

React Uncaught Error: Element type is invalid Encountering a problem in my React application where the following error message appears: Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite compone ...