Is there a way to modify the -webkit-overflow-scrolling style using JavaScript?

Is it possible to dynamically set -webkit-overflow-scrolling using JavaScript? I attempted the code below but it didn't work as expected

$("#myDiv").css("-webkit-overflow-scrolling","none");

The "myDiv" element has the .scrollable class applied with the following CSS properties

.scrollable{
             overflow-y: scroll;
             -webkit-overflow-scrolling: touch;
           }

Answer №1

To apply the webkit-overflow-scrolling CSS property using JavaScript, use the following code:

document.getElementById("myDiv").style.webkitOverflowScrolling = "auto";

Correction: "none" is not a valid value for this property, but "auto" should work as expected.

For more information on available options, refer to the documentation at https://developer.apple.com/library/safari/documentation/AppleApplications/Reference/SafariCSSRef/Articles/StandardCSSProperties.html

auto: Enables one-finger scrolling without momentum.

touch: Activates native-style scrolling, creating a stacking context (similar to opacity, masks, and transforms).

Answer №2

Why not consider creating a specific class to serve as a tool instead?

I typically use this on my website when the content width is less than 700px.

.device-touch-tool {
  @media (max-width: 700px) {
    -webkit-overflow-scrolling: touch;
    overflow-y: scroll;
  }
}

This way, you can easily apply it by simply doing the following:

$("#myDiv").addClass('device-touch-tool');

It's interesting that this question was posed nearly four years ago! :-)

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

Exploring the possibilities of reading and writing data in localStorage?

Just starting out with Phonegap, jQuery Mobile, and HTML5 - so please bear with me as I navigate through this learning process! I'm having an issue and could use some help. When trying to use a variable from localStorage, the screen remains blank whe ...

Tips for applying various classes using ngClass to enable an animation when a value changes compared to when that value is true when the page first loads

I need some help with a coding issue, could someone assist in making my question clearer? I'm working on creating an animation that triggers when the value of an object changes. I used ngClass to assign a class to an element based on the object' ...

Implementing a JQuery script that triggers every time there is a change in the scroll

This script creates a shrinking effect on a box followed by a fade-in/out transition when the scroll position changes. However, the issue is that it triggers every time there is a scroll position change. For example, if the scroll position is at 100px and ...

PHP JSON not working with Date Picker

My goal is to extract dates from a database and store them in a JSON format. These dates are intended to be used as unavailable dates in a datepicker. However, I am facing an issue where the datepicker is not displaying at all. checkDates.php ...

Enhancing features with jQuery's .animate() function

Can anyone help me figure out why the div on the right is not pushing itself away from the one on the left when I hover over it? I want it to move on mouseenter and return to its original position on mouseleave. The changing background colors are just ther ...

Finding the precise top offset position with jQuery upon scrolling – a step-by-step guide

I need help with detecting the offset top of a TR element when it is clicked. It works fine initially, but once the page is scrolled, the offset().top value changes. How can I resolve this issue? $(function() { $('tr').click(function() { ...

"Modify hyperlink attributes to enhance security and optimize user experience

$("a[href*='youtube']").attr('rel', 'prettyPhoto'); Having some trouble targeting links on a page containing "youtube" in the URL. I'm trying to set their rel attribute to "prettyPhoto" so they open in a lightbox window. ...

Is it dependable to use jQuery to trigger ajax upon click in order to reliably work sequentially on the database?

Imagine there are 4 radio buttons on a webpage, and when any of them is clicked, it triggers an ajax call to save the button's value in a database. If the user clicks the first radio button (with a value of 1), an ajax call will be made to save this ...

I'm puzzled as to why implementing jQuery UI autocomplete on my dropdowns is also affecting my listbox

I have been attempting to update my comboboxes to utilize autocomplete, so I found this code (which worked beautifully for my dropdown menus) The problem arises when I also have a listbox on the same page with the following code: <%= Html.ListBox("Car ...

Understanding the process of retrieving the value of an element produced in a PHP foreach loop

I am faced with an issue in my code where elements are being generated within a for loop using PHP. Here is the snippet of the code: for($i=0; $i < $count; $i++) { $member = $my_array[$i]; <td><span id="myspan"><input type="text" id= ...

Leveraging Jquery Splice

Trying to eliminate an element from an array using the Splice method. arrayFinalChartData =[{"id":"rootDiv","Project":"My Project","parentid":"origin"},{"1":"2","id":"e21c586d-654f-4308-8636-103e19c4d0bb","parentid":"rootDiv"},{"3":"4","id":"deca843f-9a72 ...

I would like to know the method for inserting an HTML element in between the opening and closing tags of another HTML element using

Recently, I came across a coding challenge involving a textbox. <input type="text></input> The task was to insert a new span element between the input tags using jQuery, as shown below: <input type="text><span>New span element< ...

Arranging a content container beneath a div containing an image

On a webpage I am working on, there is a div that contains an animation with images that change using CSS. Below this animation is a wrapper div for the content structured like this: <div id="animation"> <img ...> ... <img .. ...

Is the CSS class turned off?

When pulling avatar images for my vBulletin forum, the code used is as follows: <img src="{vb:raw post.avatarurl}" alt="{vb:rawphrase xs_avatar, {vb:raw post.username}}" title="{vb:rawphrase xs_avatar, {vb:raw post.username}}" class="forumavatar1" /> ...

utilizing jsTree in combination with MVC .net

I'm working on an MVC project and encountering issues while trying to trigger a method within the controllers object. Below is the snippet of code where I am facing challenges: .NET Namespace WindowTreeView Public Class DefaultController Inherit ...

How can you inform TypeScript about a file that will be included using a script tag?

I am currently utilizing TypeScript for my front-end JavaScript development, and I have a situation where I am loading two scripts from my index.html file as shown below: <script src="replacements.js"></script> <script src="socket.js">&l ...

HTTP request form

I'm currently working on a form that utilizes XMLHttpRequest, and I've encountered an issue: Upon form submission, if the response is 0 (string), the message displayed in the #output section is "Something went wrong..." (which is correct); Howe ...

The screen reader is unable to interpret the text that is visible within the anchor tag

I have an Angular application with a dropdown menu implemented as shown below. When using the NVDA screen reader to navigate, only the content inside the aria-label attribute is being read when tab focused. However, I want it to also read the content (&ap ...

I am struggling to get my card content to align perfectly in bootstrap 5

I'm having trouble centering all the content in my cards, as it keeps aligning to the right side Here is my card code: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="wid ...

Laravel error code 500 when executing a basic jQuery Ajax request

Currently, I am experimenting with some basic ajax requests and encountering a 500 error code when trying to respond with the controller displaying an Internal Server Error 500 Below is my web.php file: This section functions without any issues //Route: ...