Solution to overflow: Auto in mobile safari

Source: Internet
Author: User
This time, there was a project that needed full support for iPad, and many problems were encountered in the middle. Today there is a div that requires a scroll bar to expire under the safari of the iPad. mobile safari removes the scroll bar in the local area due to multi-touch (to prevent conflicts with the default drag behavior ). First, it ruled out whether it was caused by layout problems. Therefore, a simple page was created for testing and still failed. Google found that there was such a problem, and Google Reader also failed, mobile safari requires two fingers to complete partial scrolling. In order to solve this problem, continue to Google, and finally found the above article Article Use the touchmove event of mobile safari to simulate the effect of the scroll bar. Not much nonsense Code Function istouchdevice (){ Try { Document. createevent ("touchevent "); Return true; } Catch (e ){ Return false; } Function touchscroll (ID ){ If (istouchdevice () {// If touch events exist... VaR El = Document. getelementbyid (ID ); VaR scrollstartpos = 0; Document. getelementbyid (ID). addeventlistener ("touchstart", function (event ){ Scrollstartpos = This. scrolltop + event. Touches [0]. Pagey; Event. preventdefault (); }, False ); Document. getelementbyid (ID). addeventlistener ("touchmove", function (event ){ This. scrolltop = scrollStartPos-event.touches [0]. Pagey; Event. preventdefault (); }, False ); } Finally, use touchscroll ("myelement"); call this method by calling the element ID of overflow: auto.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.