Improving the touch responsiveness of my website's navigation menu (drop-down style)

I am currently developing a small website that includes a simple drop down menu feature. When using a desktop, hovering over an item triggers the drop down list, which is straightforward. However, on touch screens, this functionality is not working properly. I can click on an item to generate the drop down, but I am unable to close it by clicking on the parent menu item.

Unfortunately, I lack expertise in JavaScript, so I am having trouble implementing the solutions I have come across on this platform.

Here is my website on jsfiddle: https://jsfiddle.net/y1v8zsc5/

You can also view a live version at: raihansharif.site90.com

The code is quite lengthy...

HTML:

<body>
  <div id="wrapper">
    ...
  </div><!-- wrapper -->

</body>

CSS:

/* CSS styles */
...

/* CSS styles continued */
...

/* Additional CSS styles */
...

JavaScript:

$('.hamburger').on('click', function(e) {
  // Prevent link from jumping to the top of the page
  e.preventDefault();
  // Toggle slide down effect for the menu
  $('.menu').toggleClass('slide-down');
});

document.addEventListener('touchmove', function(e) {
    e.preventDefault();
    var touch = e.touches[0];
    alert(touch.pageX + " - " + touch.pageY);
}, false);

Answer №1

Instead of using the touchend listener type specifically for the menu items, you have mistakenly applied the touchmove listener type to the entire page.

$('.menu li').addEventListener('touchend', function(e){
    e.preventDefault();
    $(this).find('ul').toggle();
});

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

Triggering the onClick event in React to invoke another class components

I'm currently working on implementing a modal popup (stored in the PostView class) so that it appears when any post in the postcontainer class is clicked. As I am new to React, I would greatly appreciate any suggestions for enhancing the code. Post C ...

Incorporating the inputted year into the AJAX request

At page A, there is a form that includes an input field for the year and a dropdown menu for selecting a month. <form method="post" action="" name="form_cal" id="form_cal" class="inputform"> <div class="h5"><stro ...

Eliminate Bootstrap's validation glyphs

Issue Description I am attempting to eliminate the validation icons from Bootstrap, such as the "x" and "check" symbols. Despite my efforts to search thoroughly, I have been unable to locate where these icons are located in the code. Code Sample You can ...

Can a href from a "<Link>" component be passed through a Higher Order Component (HOC) into an "<a>" tag?

I am currently facing a situation with the main component where I have the following code: <Link href={'test'}> <PrimaryAnchor>Welcome</PrimaryAnchor> </Link> Within the PrimaryAnchor component, the code looks like ...

Tips for Integrating a Facebook Shop Page into Your Website

Can a Facebook shop page be integrated into a website? Any guidance on how to accomplish this task would be greatly valued. ...

Interacting with dynamically created input fields using Jquery from a JSON loop

I'm stuck trying to figure out why this code isn't working for me. I'm attempting to retrieve the value of a textfield that was generated via a loop from a JSON file. At the end of this code, I've added a simple click(function() {alert ...

Moving through divisions that share a common class name using jquery

I am experimenting with a plugin that allows me to attach popups to images. My goal is to enable navigation between all popups using previous and next buttons upon clicking on a popup. Below is the element when it's displayed: <div class="imp-too ...

The accumulation of input using setInterval is not effective

I need some help with my code. Please take a look at this link here. I want the input to count up from zero and hide when I click the "change" button. But when I show the input again, I want its value to reset back to zero. Can anyone guide me on how to ...

What is the complete pathway in CSS?

Consider this scenario: within my CSS file, there is a line of code used to display an image - specifically, a label icon located in the sidebar. background-image:url(../assets/images/icons/arrow_state_grey_expanded.png); However, due to its relative pat ...

Develop a custom cell editor for ag-Grid and insert it into a designated location within

I am currently working with Angular 16 and AgGrid 30. My goal is to have the cell editor created in a different location than its default position, which is within a div element at the bottom of the body with these classes: ag-theme-material ag-popup. I w ...

Vue initialization encounters an issue with starting 'marker-animate-unobtrusive' package

I am encountering an issue with marker-animate-unobtrusive and keep receiving the following error: https://i.sstatic.net/Y69xK.png While browsing through SO, I came across a post discussing the importance of requiring the file after Google has loaded. Ho ...

"Encountering difficulties in utilizing the Chrome message passing API through Selenium's execute_script function

Currently, I am trying to send a value to a chrome extension from a browser automation script by invoking the chrome.runtime.sendMessage API from Selenium. Below is the python code I am using: import os import time from selenium import webdriver from sele ...

Guide to creating a responsive layout using CSS and HTML

I am looking to position the main contents (content 1 and content 2) in between two side menus on my exercise page. At the moment, the main contents are overlapping with the two menus. Can someone guide me on how to fix this alignment issue? Thank you. ...

Is it possible to assign a class or id to a dynamically inserted link using JavaScript?

Currently, I have code that effectively inserts a link to the selected text: document.execCommand('CreateLink', false, 'link.com') Although this method works well, I am eager to include a class/id for the link to simplify styling it w ...

Enhanced JavaScript Regex for date and time matching with specific keywords, focusing on identifying days with missing first digit

I have a specific regular expression that I am using: https://regex101.com/r/fBq3Es/1 (audiência|sessão virtual)(?:.(?!audiência|sessão virtual|até))*([1-2][0-9]|3[0-1]|0?[1-9])\s*de\s*([^\s]+)\s*de\s*((19|20)?\d\d) ...

Unable to access Form element in Firefox browser

I'm struggling with debugging unfamiliar problems. For instance, in my HTML there's a form: <form name="myForm" > <table> <tr> <td> <input type="radio" name="myType" value="val" onclick="someF ...

Learn how to monitor and analyze hard drive usage and statistics on Windows and Mac systems by utilizing node.js or electronjs

Is there a way to retrieve hard disk utilization, idle time, and HDD type using JavaScript specifically for Windows and MacOS operating systems? I have access to the nodejs and electron API for my application. I have been struggling to find any API or np ...

Transmitting various pieces of information using AJAX

Is it possible to send both "credit_uri" and "address" strings in one AJAX request? Currently, only the second string is being sent. How can I include both in the data of the request? $.ajax({ url: '#{add_cards_path}', type: 'POST&apo ...

Invoking a Directive within another Directive

Feel free to check out this demo on Plunkr. I've set up a basic structure: <body ng-app="myApp"> <div ng-controller="myController"> <parent-directive></parent-directive> <child-directive></child-direc ...

Transforming a string into a JavaScript array using regular expressions

Excuse me if this question has already been asked (this is my first time asking). The content of my string looks like this (after removing the whitespace): "#home #blog description of page here ##article1 ##article2 #contact" When parsed, it will produce ...