What is the Mobile Safari event for the on-screen keyboard closing?

試著忘記壹切 提交于 2019-12-23 15:07:09

问题


I'd like to run a $('html, body').animate({ scrollTop: 0 }, 0); anytime the on-screen keyboard is closed in my iPad web app. I've tried with .blur(); but that causes problems if the user focuses on the next or previous field directly from the on-screen keyboard.

Does closing the keyboard trigger an event of any sort? That would be the most stable route for me to go.


回答1:


Switched the event to blur() and it seems to work a lot better with the iPad, Playbook still does some strange things. I don't think the event firing is quite there for the Playbook yet.

// Check for dirty inputs
$("form :input").blur(function()
{
    // FORCE THE PAGE BACK TO THE TOP   
    $('html, body').animate({ scrollTop: 0 }, 0);           
});



回答2:


I tried checking for dirty inputs and it seems the selector fires after the keyboard is closed, so I put your code in there and it worked like a charm:

// Check for dirty inputs
$("form :input").change(function()
{
    // DO OTHER HOUSE KEEPING HERE

    // FORCE THE PAGE BACK TO THE TOP   
    $('html, body').animate({ scrollTop: 0 }, 0);           
});

This is working on ipad without any quirks. On the Playbook it looks like the user has to select the "return" button then close the keyboard for the change function to fire correctly.



来源:https://stackoverflow.com/questions/7481465/what-is-the-mobile-safari-event-for-the-on-screen-keyboard-closing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!