What could be causing the issue with hammer.js swiping functionality on iPhones?

Looking for assistance from those experienced with hammer.js, as I'm facing an issue with swiping/scrolling on iPhones.

I have been developing a web app using 8thwall and hammer.js for swipe and scroll functionality. While testing on my Samsung Galaxy S10, everything works perfectly. However, when testing on various iPhone models such as iPhone 8 Plus, iPhone XR, and iPhone 6s, the swiping and scrolling do not function at all. Any guidance on how to resolve this would be greatly appreciated. Thank you.

Here are snippets of my code:

//SCROLLING FUNCTION
AFRAME.registerComponent('scroll-lines', {
    init: function(){
        var container = document.getElementById("scrolling-container");
        var content = document.getElementById("button-collections");
        var hammer = new Hammer(container);

        var initialX = 0;
        var deltaX = 0;
        var offset = initialX + deltaX;

        hammer.on("panleft panright", function(ev) {
            deltaX = ev.deltaX;
            offset = initialX + deltaX;

            container.scroll(-offset, 0);
        });

        Hammer.on(container, "mouseup", function(e) {
            initialX = offset;
        });
    }
})

<!--SCROLLING BUTTONS-->
<div id="scrolling-container">
    <div id="button-collections">
        <div id="box-all" class="cantap"></div>
        <div id="box-seremban" class="cantap"></div>
        <div id="box-klang" class="cantap"></div>
        <div id="box-ampang" class="cantap"></div>
        <div id="box-petaling" class="cantap"></div>
        <div id="box-kj" class="cantap"></div>
        <div id="box-ekspres" class="cantap"></div>
        <div id="box-transit" class="cantap"></div>
        <div id="box-monorail" class="cantap"></div>
        <div id="box-kajang" class="cantap"></div>
        <div id="box-skypark" class="cantap"></div>
    </div>
</div>

The CSS:

#scrolling-container{
    z-index: 10;
    position: absolute;
    display: flex;
    top: 55%;
    width: 100%;
    cursor: pointer;
    background-color: red;
}
#button-collections{
   display: flex;
   flex-direction: horizontal;
   overflow: scroll;
   height: 150px;
   padding-top: 170px;
   width: 100%;
}

UPDATE: Tried suggested solutions but no resolution. Discovered that using var hammer = new Hammer(container); works for Android but not iOS. Meanwhile, var hammer = new Hammer(content); works for both platforms, though there's an issue with scrolling to the end on mouseup for both iOS and Android when utilizing panleft, panright, and panend events.

UPDATE 2: As hammerjs is somewhat functional on iPhones now, the initial question has been partially answered. Closing this query and opening a new one to address the current situation.

Answer №1

Are you certain about using pan as the gesture? Pan is primarily used for dragging. In hammer.js, swipe is referred to as swipe. It's possible that the correct gesture is triggered on Android but not on iPhone. If you move your finger quickly, it registers as a swipe rather than a pan. Also, consider using panend instead of mouseup, as Android may trigger mouseup events while iPhone does not.

The potential events associated with pan are:

  • panstart
  • panmove
  • panend
  • pancancel
  • panleft
  • panright
  • panup
  • pandown

Answer №2

It is recommended to opt for swipeleft and swiperight events over pan events for better performance.

Answer №3

On iOS, if the elements do not have a defined cursor, the client-side events mousedown and mouseup necessary for swipe functionality will not be triggered. For more information, refer to How to make my 'click' function work with iOS.

If you detect an iOS device, add a class ios-device to your <body> tag and apply the following style:

body.ios-device {
    cursor: pointer !important; /* This is essential for click events on iOS! */
}

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

Unable to retrieve DateTime.Now as a string within a Razor view

I am trying to retrieve the current time in a Razor View and utilize it in JavaScript, as demonstrated below: @{ string fileName = "Score_List_" + DateTime.Now.ToShortDateString(); } <script> // assigning C# variable to JavaScript variabl ...

Is there a way to transform a string property into a custom type in a TypeScript array?

I am faced with a situation where I have an interface that is extending a MongoDB document, along with some sample data that is also extending that interface. Below is an outline of the interface: export default interface IModel extends Document { _id: Obj ...

Is it possible to programmatically bind a click event to each individual word in a div element?

I'm attempting to link each word within an element without altering the markup inside the element using Javascript. ...

Icon for TypeScript absent from npm package listings

Recently, I created a package and uploaded it to the npm repository. The package was displayed with an icon labeled "ts" on the website. https://i.stack.imgur.com/LoY1x.png The accompanying package.json showcased the inclusion of the "ts" icon - https:// ...

Small jumps occur when implementing the scrollTop jquery animation

I've encountered an issue with the scrollTop jquery animation that I can't seem to resolve. It seems to micro-jump right before the animation, especially when there is heavier content. I'm puzzled as to why this is happening... Here's ...

Guide to centering images with HTML and CSS

I've recently created a website with a homepage design that I'd like to tweak. Currently, the layout looks like this : https://i.stack.imgur.com/5UeUn.jpg My goal is to reposition the ficstore logo to the center and divide the bar into two halv ...

Update the content inside a <p> tag dynamically using Javascript based on the selected option

Struggling with Javascript and need some guidance. I have a select box with 4 options, and I want to update the contents of a <p> tag with an id of pricedesc based on the selected option. Here is my current code: function priceText(sel) { var l ...

Unable to connect to Server API endpoint

Encountering an issue while trying to access the API endpoint from server.js that connects to Spotify API. Below is my server.js code: // server.js const express = require('express'); const app = express(); const dotenv = require('dotenv&apo ...

The mega menu is malfunctioning differently across various browsers and causing issues with responsiveness

I've encountered a strange issue with my portfolio website. While everything works smoothly in Google Chrome, I'm experiencing problems with the mega menu responsiveness on other browsers like Firefox, Microsoft Edge, and Opera Mini. Visit the ...

One issue with displaying iAd over UITabBar in a UITableView using Objective-C is that the TableView may not appear below the iAd banner

I'm attempting to achieve a similar outcome to the post displayed here: This is my approach: I have a question: Is it normal that I can't fully drag the banner? However, the result I'm getting is: Ignoring the fact that the iAd isn' ...

Unable to access property within JSON object sent via POST request

I encountered an issue TypeError: Cannot read property &#39;tasks&#39; of undefined While attempting a new POST request on my API, here is the request body I am using: { "name": "example1", "description": "teaching example1", "rules" ...

What is the best method to incorporate a JavaScript object key's value into CSS styling?

I am currently working on a project in React where I'm iterating over an array of objects and displaying each object in its own card on the screen. Each object in the array has a unique hex color property, and my goal is to dynamically set the font co ...

Is there a way to inform TypeScript that the process is defined rather than undefined?

When I execute the code line below: internalWhiteList = process.env.INTERNAL_IP_WHITELIST.split( ',' ) An error pops up indicating, Object is possibly undefined. The env variables are injected into process.env through the utilization of the mod ...

Constructing the necessary gulp configuration file

When using Gulp and Gulp-sass, with the use of 'gulp.watch', how can I retrieve the directory name of the modified item on the watchlist in order to compile the sass to css? Currently, the setup only compiles the sass files from theme 1. If ther ...

Exploring ways to loop through objects in a React application

I'm trying to figure out how to modify the code below to iterate through a custom object I have created. function itemContent(number) { return ( <div > <div className="item"> <div className="itemPic& ...

What is the process for implementing a custom error when compiling Sass code with node-sass?

When using node-sass to compile my sass code, I am curious about the possibilities during the compilation process. To clarify, I am interested in creating custom rules and generating specific errors under certain conditions while compiling. ...

Listening for events on a canvas positioned beneath another element

I am currently dealing with an issue where I have a mouse move event listener set up on my canvas element. However, there is a div placed on top of the canvas with a higher z-index, which contains some menu buttons. The problem arises when I want the mous ...

Tips for resolving the issue of missing metadata for open graph and Twitter cards in a Next.js project

Having trouble with error messages while running the build version in Next.js. I've added meta tags to the layout, but the issue persists. As a newcomer to Next.js, I'm looking for guidance on how to fix this problem. Any help or advice on troubl ...

VueJS Element Library's date picker feature returns dateTime values with their corresponding time zones attached

I'm currently utilizing a date picker from The expected format for the date should be: yyyy-MM-dd However, the actual returned date format is: Thu Apr 20 2017 00:00:00 GMT+0530 (India Standard Time) This is the code snippet I've used: & ...

In React, the input is consistently considered 'valid'

I have a React component that looks like this export const SearchBar = ({ searchInput, updateSearchKeyword, }: SearchBarProps) => { const dummy = ""; return ( <div className={`${styles.container} `}> <input c ...