IOS 5 (safari) bug with HTML touch events on “position:fixed” div

前端 未结 7 1954
执念已碎
执念已碎 2021-02-05 22:32

I have a position:fixed div on a scrolling web page.

At first the event works, but when the page scroll, while the fixeed divs stays in place, its \"touch\" zone seems t

相关标签:
7条回答
  • 2021-02-05 22:58

    Touch events retrieve pageX and pageY - which suggests a position on the 'page' is meant. If the page is scrolled down, the Y coordinate increases and thus fixed elements will be out of reach because their y offset values stay the same. You can check wheter a fixed element has been touched on a scrolled page by this calculation:

    var finger = e.touches[0];
    var yCalc = finger.pageY - window.pageYOffset;
    var touchedElement = document.elementFromPoint(finger.pageX, yCalc);
    

    If you have horizontal scrolling, you have to do the same thing with the x coordinate, of course.

    0 讨论(0)
提交回复
热议问题