Preventing touch scrolling within a container with an overflow set to scroll/auto feature and enabling dragging within the container

Help needed: Issue with scrolling inner div within draggable outer div.

I am facing an issue where I am unable to scroll the inner box properly on my iPad. The problem arises when I try to scroll the inner box, and the outer box starts moving instead.

I am using the jQuery UI library for the draggables.

For reference, you can check out this example:

Example

HTML:

<div id="outer">
 <div id="inner">
  A<br/>B<br/>C<br/>D<br/>E<br/>F<br/>G<br/>H
 </div>
</div>

JS:

$('#outer').draggable();

CSS:

#outer{
    position: fixed;

    top: 20px;
    left: 20px;

    width: 400px;
    height: 300px;

    border: 1px solid black;
}

#inner{
    position: absolute;

    top: 10px;
    left: 10px;

    width: 200px;
    height: 100px;

    overflow: auto;

    border: 1px solid red;
}

Your help and advice are highly appreciated. Thank you in advance!

Best regards, yannic

Answer №1

I am pleased to share that I have successfully resolved my issue:

I have implemented touch scrolling functionality for the box itself.

var TOUCH_MOVE_TEST_X = undefined;
var TOUCH_MOVE_TEST_Y = undefined;

$('#inner').bind('touchstart', function(event){

    TOUCH_MOVE_TEST_X = event.originalEvent.touches[0].clientX;
    TOUCH_MOVE_TEST_Y = event.originalEvent.touches[0].clientY;

    return false;
});

$('#inner').bind('touchmove', function(event){

    event.srcElement.offsetParent.offsetParent.scrollLeft = event.srcElement.offsetParent.offsetParent.scrollLeft + ( TOUCH_MOVE_TEST_X - event.originalEvent.touches[0].clientX );                                                         
    TOUCH_MOVE_TEST_X = event.originalEvent.touches[0].clientX;                                                         

    event.srcElement.offsetParent.offsetParent.scrollTop = event.srcElement.offsetParent.offsetParent.scrollTop + ( TOUCH_MOVE_TEST_Y - event.originalEvent.touches[0].clientY );                                                           
    TOUCH_MOVE_TEST_Y = event.originalEvent.touches[0].clientY;

    return false;
});
$('#inner').bind('touchend', function(event){

    TOUCH_MOVE_TEST_X = undefined;
    TOUCH_MOVE_TEST_Y = undefined;

    return false;
});

Warm regards,

Yannic

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

Real-time File Updates Display with Node.js and Express.js

Seeking guidance on whether there is a Node module available to utilize the Express module for displaying real-time updates in the browser using data from a file. I have a regularly updated .csv file and I am looking to showcase these updates instantly on ...

Simpler and more sustainable methods for embedding HTML elements using a configuration file

Currently, I am devoting my time to a toy project that heavily relies on JavaScript. A key component of this project is a JSON file that contains configurations and input descriptions, along with range values and options. This JSON file enables me to easil ...

Getting the ID of a select input option in Vue.js using FormulateInput

Recently, I've been working with a FormulateInput select component that looks like this: <FormulateInput name="broj_zns-a" @change="setZns" :value="brojZnsa" type="select" label="Broj ZNS- ...

What is the best way to navigate to a different page when scrolling in React Router?

I am working on a design that includes a landing page with 100vh and 100vw dimensions. I want it to transition into another page as the user scrolls down. How can I achieve this using React hooks and React Router? Any guidance or suggestions would be high ...

Dealing with the information received from a PHP response during an AJAX request using JavaScript

Here is my PHP script <?php //establishing connection to the server //selecting the database $temporaryArray = array(); $counter = 0; $result = mysql_query("some query"); while($row = mysql_fetch_assoc($result)) { $temporaryArray["$counter"]= $row[" ...

Exploring the vulnerability in switching an ajax request to another PHP file for potential exploitation clarification

I am currently developing an application that processes an ajax call (using jquery) and provides validated users with an entry token for the website. For instance, if the ajax call is made to checkAuth.php and all other php files are in the same directory ...

JSON - The challenge of incorporating single quotes within double quotes

In my current scenario, I am using the following code to populate form fields. The code is designed to handle a JSON dataset that has been encoded with PHP's json_encode function. Everything works smoothly when dealing with either single or double qu ...

Customize the HTML tags in the Froala text editor with easy insertion and removal

In my AngularJS project, I am utilizing Froala editor. I want to create a unique functionality where a custom button wraps selected text with <close></close> tags when activated. Moreover, if the selected text is already wrapped with these tags ...

Highlighting table rows when hovering in IE with JQuery - compatibility across all versions

I have a table on my jsp page with multiple rows and columns. I want to ensure that visitors can easily follow along when they interact with the table - by highlighting the row or column they hover over with a different background color. Although the **hov ...

Leverage JSON data from an API within JavaScript, sourced and accessed through PHP

I'm seeking advice on using JSON data (loaded in PHP) with JavaScript. I am currently retrieving the JSON from an API, but someone suggested that using curl would be more efficient? I've attempted to research curl, but haven't found exactly ...

Discover how to implement custom data filtering in an Angular controller

Help needed: How can I remove decimals, add $ symbol in an Angular controller? Any ideas? $scope.data = [{ "key": " Logo", "color": "#004400", "values": [ [0, parseInt($scope.myappslogo)] ] }, { "k ...

The MongoDB operator that checks for multiple values within a specified field

I created a table with the following values: [ { id: 1, name: "abc" }, { id: 2, name: "lmn" }, { id: 3, name: "xyz" } ] My query includes $in as follows: { id: { $in: [ 2, 3, 1 ] } } I am hoping for the output to be in this or ...

Generating an HTML table with JSON data in JavaScript

I'm still struggling with JavaScript as a beginner, so please bear with me and provide guidance step by step. Also, try to avoid overwhelming the comments with links as it confuses me. This is an attempt to bypass the CORS issue. <!D ...

How can I correct the changing order of buttons when floating to the right?

When I align a few buttons to the right, the order of those buttons changes. I have included an image for reference. View Navbar Image This is the code I am currently using: .btn{ float: left; padding: 1.7em; text-align: center; display ...

What part of the system generates sessions and cookies?

Is the following statement accurate? When developing a website, I utilize frontend javascript to create cookies and backend languages such as php or ruby to manage sessions? If this is correct, does the creation of sessions involve the browser generating ...

Retrieve all image IDs based on their class name

My goal is to utilize JavaScript in order to retrieve the ID of each image on a webpage that is associated with the CSS class 'asset', and then store these IDs in a new array. While I am able to collect all the images as shown below, I now need ...

I'm puzzled as to why the navigation bar isn't staying fixed

I recently created a landing page using Bootstrap, but I'm having an issue with the navbar not being fixed. Here is the code for the navbar: <nav class="navbar fixed-top navbar-inverse bg-primary navbar-toggleable-md navbar-light bg-faded"> < ...

How can we leverage jQuery deferred within Backbone Marionette composite views, where each items view contains a form, to execute a task after each form submission is successful?

I am utilizing a Backbone Marionette composite view in which each child item view contains its own form. var DependentsFormFields = Backbone.Marionette.CompositeView.extend({ template: 'dependents_form_fields_wrapper', itemViewContainer: ...

Editify Angular Text:Note: The name 'Edit

I am currently working on a coding project that involves allowing a user to click a button on the screen and view a paragraph that they can edit. I removed the readonly part of my code, but the paragraph is still not editable. How can I make it so that the ...

Validation of VAT numbers using JavaScript instead of PHP

I came across an interesting function at this link that is used for checking VAT numbers in the EU. However, I am struggling to integrate it with my registration form. I would like to convert it into a JavaScript function so that I can validate the number ...