开发者

iPad - touchStart() event blocked by div text

开发者 https://www.devze.com 2023-03-18 07:57 出处:网络
I have a div which triggers a touchStart event: <div class="button" ontouchstart="touchStart(event)"> button</div>

I have a div which triggers a touchStart event:

<div class="button" ontouchstart="touchStart(event)"> button</div>

When my finger lands on the text button inside the div the event is not triggered, anywhere else on the surface of div event is triggered, how can I make it trig开发者_JAVA技巧ger when I touch the text as well?


if you know the size of the div, then you can add a transparent div above your text with the ontouchstart event.

<div class="buttoncontainer">
    <div class="button"> button</div>
    <div  ontouchstart="touchStart(event)" class="somethingrelative"></div>
</div>

where the buttoncontainer and somethingrelative assist in the positioning.


You can also put the text inside another element, for example a span, and make it unreactive to events with:

.button span {  
    pointer-events: none;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消