How can Swipe support help you slide a menu back in?

For implementing swipe support on my landing page carousel, I included jquery.mobile.custom.min.js.

However, I am facing a challenge with adding swipe support to "close" the menu. Essentially, swiping left should have the same effect as clicking the button.

Here is the relevant HTML:

<body>
<!-- sidebar -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <input type="checkbox" name="handler-left" class="handler" id="handler-left" onclick="null" />
     <div id = "menu">
            <ul> 
              <li><a href="index.html">Home</a></li>
              <li><a href="services.html">Services</a></li>
              <li><a href="about.html">About Us</a></li>
              <li><a href="portfolio.html#">Portfolio</a></li> 
              <li><a href="contact.html">Contact Us</a></li>
            </ul>
     </div>

<div id="wrapper">
        <p id="button">
        <label for="handler-left" id="left" href="#">Menu</label>
        </p>

My attempt at the script:

$(document).ready(function() {  
    $("menu").swipeleft(function() {  
        $(this).parent().handler('left');  
    });  
}); 

CSS for handler:

.handler {
    display: none; }
    #handler-left.handler:checked ~ #menu {
      opacity: 1;
      -webkit-transition: opacity 0s 0s;
      -moz-transition: opacity 0s 0s; }
      #handler-left.handler:checked ~ #wrapper {
        -webkit-transform: translate3D(40%, 0, 0);
        -moz-transform: translate3D(40%, 0, 0); }
        #handler-left.handler:checked ~ #wrapper #content {
          overflow: hidden; }

Progress update:

I have successfully detected a swipe on the entire document, now I need to figure out how to toggle the class.

$(document).ready(function() {               
 $(document).on("swipeleft",function(){               
    (".handler").??? });    });

UPDATE 2:

The solution has been found. Below is the piece of code that resolved the issue:

  $(document).ready(function() {  
             $(document).on("swipeleft",function(){
             document.getElementById('handler-left').click();

             // alert("you swiped left!");
});
    }); 

Answer №1

  $(document).ready(function() {  
         $(document).on("swipeleft",function(){
         document.getElementById('handler-left').click();

         // alert("you swiped left!");

}); });

Resolved the issue independently!

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

The Tab component's onClick event is nonfunctional

I am currently utilizing the Tab feature from the material-ui library in my React project. As I try to come up with a workaround for an issue I am facing, I notice that my onClick event listener is not being triggered. An example of one of the tabs: < ...

Is there a more efficient alternative to `[].push.apply(this, arr)` for combining elements in an array instance within a constructor?

It only takes 0.15ms for this line in my constructor function to execute. [].push.apply(this, selector); I'm not satisfied with the 0.15ms execution time. I believe there must be a quicker alternative available. This particular line seems to be conv ...

Changing between two images using HTML and CSS

I am currently designing a WordPress theme and I would like to create an effect where two different thumbnail images switch on hover. The code that I have come up with so far looks something like this : <a class="thumb" href="posturl"> <img src= ...

Utilize JavaScript's $.post function to export PHP $_POST data directly into a file

After spending hours trying to figure this out, I've come to the realization that I am a complete beginner with little to no knowledge of what I'm doing... The issue I'm facing is related to some JavaScript code being triggered by a button ...

What are some effective tactics for reducers in react and redux?

Working on a React + Redux project to create a web app that communicates with an API, similar to the example provided at https://github.com/reactjs/redux/tree/master/examples/real-world. The API I'm using returns lists of artists, albums, and tracks, ...

Ways to invoke a JavaScript function using a JSON string

Suppose I make an AJAX post request using jQuery with the following structure: $.post('MyApp/GetPostResult.json', function(data) { // what should be implemented here? }); When the result is as follows: { "HasCallback": true, "Cal ...

Is there a way to customize the outlined color of an input adornment in MUI?

Looking to customize the default blue color in a Form Control outlined variant, but can't figure out how. I was able to do it with a regular TextField, but this one is a bit trickier. <FormControl variant="outlined"> < ...

Utilizing local JSON data with Morris.js: A beginner's guide

I am working on dynamically plotting a Morris line using data from a local file called sales.php (in json format): [ { year: '2008', value: 20 }, { year: '2009', value: 10 }, { year: '2010', value: 5 }, { year: ' ...

AngularJS - Issue with retrieving the most recent entry during $routeChangeStart event

I am utilizing the $routeChangeStart function to redirect authorized users to specific URLs and prevent unauthorized access to special pages. In addition, I have dynamically generated pages that can be accessed via their unique page slugs. To achieve this ...

Avoiding unlimited re-renders when using useEffect() in React - Tips and Strategies

As a new developer, I recently built a chat application using socket io. In my code, I have the useEffect hook set to only change when the socket changes. However, I also have setMessage within the body of useEffect(), with socket as a dependency. Unfortun ...

ReactJS input range issue: Cannot preventDefault within a passive event listener invocation

I've been encountering some issues with the react-input-range component in my React App. It functions perfectly on larger viewports such as PCs and desktops, but on smaller devices like mobile phones and tablets, I'm seeing an error message "Unab ...

JavaScript and jQuery experiencing difficulty rendering proper style and image in output display

I am currently working on code that extracts information from a JSON variable and displays it on a map. The code looks like this: marker.info_window_content = place.image + '<br/>' +"<h4>" + place.name + "</h4> ...

React : understanding the state concept as written like ...state

As I explore React, can you please explain the significance of this piece of code to me? const new_venues = this.state.venues.map((venue) => place_id === venue.place_id ? { ...venue, open : !venue.open } : { ...venue, open: false }); I understand the ...

The conversion of string to number is not getting displayed correctly when using console.log or document.write. Additionally, the concatenated display is also not functioning as intended

Being new to JS and HTML, this program was created to enhance my understanding of the concepts. I attempted a basic program to convert a string to a number in three different ways, but I am having trouble determining if the conversion actually took place. ...

Display the user's chosen background image as the backdrop for my activity

As I've been exploring various corners of the internet, I've come across a potential technique for accessing the user's background from within my activity. I've brainstormed a couple of ideas (even though they might seem silly, just to ...

What is the best way to execute fetch calls in sequence (A -> B -> C) within a React component?

I'm facing an issue with three fetch functions - a(), b(a_id), and c(b_id). The flow is such that function a returns an a_id which is then passed to function b, and b in turn returns an id passed to function c. componentDidUpdate(prevProps) { this ...

Control the data options available in the autosuggest textbox

I have implemented an autosuggest feature in a text box with predefined values. When typing the first letter in the textbox, a dropdown displays all related values. Is there a way to limit the number of displayed related values to 20? This is what my cu ...

What is the purpose of creating a new HTTP instance for Socket.io when we already have an existing Express server in place?

As I delve into SocketIO, I've combed through various blogs and documentation on sockets. It seems that in most cases, the standard approach involves creating an HTTP server first and then attaching the socket to it as shown below: var app = express() ...

Tips for reducing code length in jQuery

Here's an interesting question that I've been pondering. Is there a more efficient way to optimize and condense code like the one below? Could it be achieved using functions or loops instead of having lengthy jQuery code? var panels = ["panel1", ...

Error encountered: The module '@mui/x-data-grid' does not export 'GridActionsCellItem'

I'm facing an issue while trying to import 'GridActionsCellItem' from '@mui/x-data-grid'. Here's the code: import { GridActionsCellItem } from '@mui/x-data-grid'; An error message pops up indicating: Attempted impor ...