Is there a way to make scrollTop function on iOS mobile devices?

I am facing an issue with a div that has CSS properties display: flex and position:fixed;. I am trying to scroll to the top of it. This functionality is working fine on all platforms except for iOS mobile devices. The scrolling does not work on iOS mobile devices in any browser.

Below is an example of the code:

function scrollToTop() {
  document.getElementsByClassName('content-wrapper').scrollTop = 100;
};
.mobile{
  /* CSS styles here */
}
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      <button type="button" onclick="scrollToTop()">
      Scroll To Top
      </button>
    <body class="mobile">

      <div class="page-wrapper">
        <div class="page-content-wrapper">
          <div class="content-wrapper">
            <div class="session-wrapper-mobile play-session-mobile">
              <!-- Content goes here -->
            </div>
          </div>
        </div>
      </div>

    </body>

Answer №1

Here is a solution for applying the correct selector based on the device being used, specifically targeting iOS devices using scrollTop.

function topScroll() {
if($.browser.safari) scrollElement = $("body"); 
else scrollElement = $("html");
scrollElement.scrollTop(100)
}

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

Steps for displaying the dropdown menu

I am having trouble with displaying the dropdown menu when hovering over the class (dropbtn). I tried adding .dropdown:hover .dropdown-content-strategy{..} but it's not working as expected. If I do manage to show the dropdown menu, it stays visible ev ...

Problem regarding data-th-id

I am facing an issue with a button that triggers a modal view and trying to capture its value using JavaScript. Here is how it's set up: <button type="button" class="btn btn-outline-primary btn-sm" data-toggle="modal" data-target="#myModal" d ...

Double Checkbox

My current project involves creating an update page, and I have successfully completed most of it except for the checkbox section. Strangely, the checkboxes are being duplicated, and I haven't been able to identify the reason behind this issue yet. Th ...

Oh no! An operational error occurred while trying to access the page "/1" because it seems like the column

I recently started working with Django and I'm trying to figure out how to display all comments related to a specific listing on an online auction site. Can anyone help me find a solution for this? Models.py class Listing(models.Model): title = m ...

(Reactjs) Steps to automate submission of file upon selection

I'm having trouble figuring out how to automatically submit an image using an input field without a submit button. My current approach involves selecting the file and then submitting it automatically. Here's what I have so far: const [image, setI ...

tips for concealing bootstrap css hover/activate color when scrolling beyond the top

Looking for help with my Bootstrap HTML code: <nav> <ul> <li><a>1</a></li> <li class="active"><a href="#">2</a></li> <li><a>3</a></li> & ...

Tips for combining HTML and JavaScript on a WordPress site

As a WordPress developer who is still learning the ropes, I have come across a challenge with embedding html and JavaScript onto a page. Currently, I am in the process of redesigning a company website and one of the tasks involves integrating a calculator ...

What is the optimal method for increasing the height of an image up to its maximum height?

I have a unique container designed to showcase images with a fixed width of 100%. Here are my specific requirements: The image must maintain its original aspect ratio. If the image is wider, the width should be 100% and the height less than the designate ...

Problem with jQuery image gallery

Currently, I am in the process of creating a simple image gallery that enlarges an image when it is clicked. To achieve this functionality, I am utilizing jQuery to add and remove classes dynamically. $(".image").click(function() { $(this).addClass("b ...

The debate between classes and data attributes in terms of auto field initialization

A Brief Background In the realm of javascript/jQuery, I've crafted a method that traverses through various fields and configures them based on their type - be it dropdowns, autocomplete, or text fields... The motivation behind this is my personalize ...

Identify Horizontal Swipe Gestures on Page-level

I am currently focused on ensuring accessibility for users utilizing voiceover technology. While navigating their phone, these individuals rely on right and left swipes to interact with elements on a page. I am seeking to implement swipe detection at the ...

I'm currently working on implementing custom hover animations for the navigation items in my React application, using Bootstrap nav. However, I'm facing an issue where

I'm attempting to implement a custom hover effect on my navigation items using external CSS. However, when I import it into my Navbar, the Bootstrap styles are not being overridden and the effect is not visible. Additionally, when the Navbar collapses ...

Restrict the height of an image based on the height of its adjacent sibling

How can I ensure that an image's maximum height matches its sibling's height, regardless of screen size? The desired outcome: Equal heights - √ An undesired outcome where the image column exceeds its sibling's height (DIV - .main-content ...

How to showcase information from a pair of database tables using a DataList element in Asp.NET

I need some assistance in displaying data from two different database tables within each datalist item. Specifically, I want to show details about a job application and then use the application owner's ID to display some of their information alongside ...

What is the best way to insert a YouTube video into a WordPress template page?

I decided to create a new template page for one of the pages on my WordPress site because I only wanted to have some text and a YouTube video displayed. It turns out that embedding a YouTube video directly into the code is not supported by WordPress, so I ...

Show a picture on top of another picture

Is there a way to overlay an image and text on top of another image, similar to what is done on this website ? ...

The issue with CSS3 rotate3d rotation

I'm facing an issue with the rotate3d function. Take a look at this Fiddle: https://jsfiddle.net/c3snpkpr/ The problem arises when hovering over the <div> from the left or right - sometimes it rotates properly, and other times it bugs out by r ...

Unable to choose an input form within a CSS div

Just installed a jQuery responsive menu tab but encountering issues with selecting forms to input values. It seems like a CSS problem that I cannot identify. Please assist me in resolving this issue. Below is the HTML code snippet: <div class="contai ...

Automatically submit HTML form data as a JSON object to an API endpoint

I am working on incorporating an online form from Formstack onto a website, and the form's code is in HTML. However, I am seeking assistance in configuring it so that whenever a user submits information through the form, it will automatically send me ...

drop down menu in navigation bar: unable to display items

I am having trouble with a dropdown menu in my code. Even though I used the code from the official Bootstrap website, the items are not appearing in the dropdown list. <nav class="navbar navbar-expand-lg navbar-dark bg-primary "> ...