Git Product home page Git Product logo

Comments (6)

john-doherty avatar john-doherty commented on June 16, 2024 1

Hello @PollerBoom, this will be happening because the child div is the one throwing the event. If you want to change the child div, you'd need to add the attribute to that item:

<div>
  <div data-long-press-delay="500">
     Sample text
  </div>
</div>

Or, you could try disabling pointer-events for the child item via CSS. This should cause the event to bubble up to the parent, example:

HTML

<div data-long-press-delay="500">
  <div>
     Sample text
  </div>
</div>

CSS

div[data-long-press-delay="500"] div {
    pointer-events: none;
}

from long-press-event.

john-doherty avatar john-doherty commented on June 16, 2024 1

HelloπŸ‘‹

I'm replying from my phone, so not able to test this. But it's generally a bad idea to attach an event to every item in a list. It's better practice to attach the event listener to the parent container, and use e.target to determine if you want to respond to the event.

Give this a try

from long-press-event.

bburns avatar bburns commented on June 16, 2024

Thanks for the library πŸ‘

Ideally the function starting the timer would check up the DOM tree until it found a data-long-press-delay value, otherwise use the default. Turning off pointer events for child elements prevents things like mouse hover from working. For now I'm just going to bring in the code and modify the value directly.

from long-press-event.

abubelinha avatar abubelinha commented on June 16, 2024

Thanks a lot for your library @john-doherty

I am not sure my problem is related to this issue or not.
Could you check this test page?
(see also longpress_test.css and longpress.js)

I intended to attach the longpress event to each item in a long list of span elements.
I want the span title tag to be shown in alert message when mobile user long-press the span.

Sometimes the span structure is like this (<span><i><b>text</b>more text</i></span>), but many other times it does not contain italics or bold tags.

With computer mouse there is no problem, but the longpress event is not fired when I use my mobile browser.
Can you test it and check the reason?

Many thanks in advance
@abubelinha

from long-press-event.

abubelinha avatar abubelinha commented on June 16, 2024

Thanks a lot for that advice. Now I am more interested in it than in my original issue πŸ˜….

So in a long list of elements, following your advice would imply what? Saving a lot of RAM because event listeners will only be attached to just a parent element and propagated to a few user-long-pressed span elements? (instead of i.e. 3000 attachments).
I have no idea about the RAM or time waste implications of each attachment.

My guess is the download size wouldn't change: in both ways the events are attached after page load.

Sorry about silly question, I am not an expert.

from long-press-event.

abubelinha avatar abubelinha commented on June 16, 2024

Also one more question: should the script with your code be put in a particular section of the html page, after/before whatever?
I don't see comments or guidelines about this, but just in case.

from long-press-event.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.