Native JS mobile Touch event for pull-up loading more

Source: Internet
Author: User

We all know that there is no touch event in jquery, so the use of native JS on the mobile side of the pull-up loading effect is very good, gossip not much to say, the code is as follows:

1 //gets the element to manipulate2 varObjsection = document.getElementsByTagName ("div") [0];3 //to bind an element to listen to an event personal habits write a listening event in a piece4Objsection.addeventlistener ("Touchstart", Touchstart,false);5Objsection.addeventlistener ("Touchmove", Touchmove,false);6Objsection.addeventlistener ("Touchend", Touchend,false);7 8 //Touchstart the method to execute when triggering an event9 functionTouchstart (event) {Ten Event.preventdefault (); One      This. Starty = Event.changedtouches[0].pagey; A } -  - //TouchMove method of executing a process triggering an event the functionTouchMove (event) { -     varChange = Event.changedtouches[0].pagey- This. Starty; -      This. Change =Change ; -      This. parentnode.style["-webkit-transform"] = "translate (0," + This. Change + "px"); +      This. parentnode.style["Transform"] = "translate (0," + This. Change + "px"); -      This. parentnode.style["-webkit-transition"] = "All" + 0 + "s"; +      This. parentnode.style["transition"] = "All" + 0 + "s"; A } at  - //Touchend Event End Execution Method - functionTouchend (event) { -     if( This. Change < 0) { -          This. parentnode.style["-webkit-transform"] = "translate (0," + This. Change + "px"); -          This. parentnode.style["Transform"] = "translate (0," + This. Change + "px"); in          This. parentnode.style["-webkit-transition"] = "All" + 1 + "s"; -          This. parentnode.style["transition"] = "All" + 1 + "s"; toAppendData ( This); +}Else { -          This. parentnode.style["-webkit-transform"] = "translate (0," + 0 + "px)"; the          This. parentnode.style["Transform"] = "translate (0," + 0 + "px)"; *          This. parentnode.style["-webkit-transition"] = "all" + 0.5 + "s"; $          This. parentnode.style["transition"] = "all" + 0.5 + "s";Panax Notoginseng     } -}
Pull up load more places to note: In the trigger pull this action to record the current page of the Pagey, at the end of the action recorded in the page Pagey, the end of the pagey-at the beginning of the Pagey to change Pagey, in doing CSS3 animation need to use the change of Pagey, Touchend inside the AppendData method for Ajax Request data method, not in here to repeat
Simple implementation of the basic functions, if necessary, can be based on the implementation of more functions
You are welcome to criticize

Native JS mobile Touch event for pull-up loading more

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.