是什么触发了 mobile safari (iPad) 上的模糊事件

发布于 2024-10-18 13:23:21 字数 326 浏览 3 评论 0原文

我有一个日期选择器控制器,当用户触摸屏幕上不是日期选择器的某个位置时,我想模糊该控制器。我遇到的问题是我不明白是什么触发了模糊事件。例如,如果用户触摸下个月,则会触发模糊事件,所以我想说,好的,如果 relatedTarget 是 datepicker 内的类(下个月),则显示下个月并且不要隐藏 datepicker,如果 relatedTarget 是不在日历上隐藏它。问题是相关目标 始终是未定义的。

所以我有两个问题:

  1. 什么会触发移动 Safari 上的模糊事件?
  2. 为什么 event.latedTarget 属性在移动版 Safari 中始终未定义?

I have a datepicker controller that I want to blur when the user touches somewhere on the screen that is not the datepicker. The problem that Im having with this is that I dont understand what triggers the blur event. For example if the user touches next month the blur event is triggered, so I would like to say, ok if the relatedTarget is a class inside the datepicker (next month) then show the next month and dont hide the datepicker, if the relatedTarget is not on the calendar hide it. The problem is that relatedTarget
is always undefined.

So I have two questions:

  1. What trigers the blur event on mobile Safari?
  2. Why is the event.relatedTarget property always undefined in mobile Safari?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鹊巢 2024-10-25 13:23:21

在这里找到:http://developer.apple.com/library/IOs/#documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW5

以下注释:
iOS 注意:虽然不支持拖放,但您可以使用触摸事件产生相同的效果,如 Safari CSS 视觉效果指南中的“使用触摸拖动元素”中所述。
卸载事件可能无法按预期进行前后优化。请改用 pageshow 和 pagehide 事件。”

HTH

Found out here: http://developer.apple.com/library/IOs/#documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW5

the following note:
"iOS Note: Although drag and drop are not supported, you can produce the same effect using touch events as described in “Using Touch to Drag Elements” in Safari CSS Visual Effects Guide.
The unload event may not work as expected for back and forward optimization. Use the pageshow and pagehide events instead."

HTH

伏妖词 2024-10-25 13:23:21

老帖子,但也许对未来参考有帮助。

前几天遇到了同样的问题。关于你的第一个问题:什么触发了移动 Safari 上的模糊事件? ->如果发生触摸事件 (iPad/iPhone),则不会触发。

我通过在封闭的 div 上设置事件侦听器来处理它。与您(至少我)的预期相反,您想要听到的事件是“点击”。下面是简化的情况:

<div id="enclosing-div">
  <input type="date" "id="date-picker-field">
  <!--Whatever other elements you might have in the enclosing div-->
</div>

现在你的 js 可能看起来像这样:

//js

//Get the enclosing div
var enclosingDiv = document.getElementById('enclosing-div');
//Set up an event listener
enclosingDiv.addEventListener('click', blurEnclosedElements);

//function to handle the event listener
function blurEnclosedElements(){
  //Get the element(s) you want to blur and apply your blur logics to it
}

Old post, but maybe helpful for futere reference.

Ran in to the same problem the other day. Regarding your first question: What triggers the blur event on mobile Safari? -> It's not triggered in case of a touch event (iPad/iPhone).

I dealt with it by setting an event listener on the enclosing div. Contradictionary to what you (at least I) might expect, the event you'll want to listen to is 'click'. Below the simplified situation:

<div id="enclosing-div">
  <input type="date" "id="date-picker-field">
  <!--Whatever other elements you might have in the enclosing div-->
</div>

Now your js might look like this:

//js

//Get the enclosing div
var enclosingDiv = document.getElementById('enclosing-div');
//Set up an event listener
enclosingDiv.addEventListener('click', blurEnclosedElements);

//function to handle the event listener
function blurEnclosedElements(){
  //Get the element(s) you want to blur and apply your blur logics to it
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文