Javascript-iPhone slide to unlock JavaScript-cancel the default browser prompt when dragging an image

Source: Internet
Author: User
<SCRIPT type = "text/JavaScript"> VaR Untilevent = {Addevent:  Function  (Oelement, otype, fun) {oelement. attachevent ? Oelement. attachevent ("On" + otype, fun): oelement. addeventlistener (otype, fun, False  );}, Removeevent:  Function  (Oelement, otype, fun) {oelement. detachevent ? Oelement. detachevent ("On" + otype, fun): oelement. removeeventlistener (otype, fun, False  ) ;}} Window. onload = Function  (){  VaR OPAR = Document. getelementbyid ("iPhone" );  VaR Odiv = Document. getelementbyid ("Lock" );  VaR Ospan = odiv. getelementsbytagname ("span") [0 ];  VaR Spanw = Ospan. offsetwidth;  VaR Divw = Odiv. offsetwidth; VaR Downx = 0 ;  VaR Movex = 0 ;  VaR Movekg = True  ;  VaR Mdown = Function  (Event ){  VaR Ev = event | Window. event; downx = Ev. clientx; untilevent. addevent (ospan, "Mousemove", Mmove); untilevent. addevent (document, "Mouseup" , MUP );  If  (Event. preventdefault) {event. preventdefault (); event. stoppropagation ();}}  VaR Mmove = Function  (Event) {EV = Event | Window. event;  If  (EV. cancelbubble) {eV. cancelbubble = True ; EV. returnvalue = False  ;} Movex = Ev. clientx;  VaR Movelenght = movex- Downx;  If (Movelenght> 0) {movelenght = math. Min (movelenght, divw-spanw )} Else  {Movelenght = 0 ;} Ospan. style. Left = Movelenght + "PX" ;} VaR MUP = Function  () {Untilevent. removeevent (ospan, "Mousemove" , Mmove); untilevent. removeevent (document, "Mouseup" , MUP );  If (Ospan. offsetleft> = (divw- Spanw) {OPAR. style. Background = "URL ('HTTP: // FGM. CC/iPhone/2.jpg ')" ; Ospan. style. Background = "NONE" ;}  VaR Dirdbms = ospan. offsetleft> (divw/2-spanw + 20 )? True: false; VaR Setint = setinterval ( Function  (){  If  (Dirdbms) {ospan. style. Left = Math. Min (divw-spanw, (ospan. offsetleft + 15) + "PX" ;  If (Ospan. offsetleft> = (divw- Spanw) {OPAR. style. Background = "URL ('HTTP: // FGM. CC/iPhone/2.jpg ')" ; Ospan. style. Background = "NONE"; Clearinterval (setint );}}  Else  {Ospan. style. Left = Math. Max (0, (ospan. offsetleft-15) + "PX" ; Ospan. offsetleft <= 0 && Clearinterval (setint );}}, 30 )} Untilevent. addevent (ospan, "Mousedown" , Mdown );} </SCRIPT>

 

I. Implementation Functions

1. Automatically slide to the left when the slider moves to the center, to the Starting Point

2. When the slider exceeded the middle, it automatically goes to the right, slides to the end, and unlocks

3. Move the slider to the terminal to unlock

 

Ii. Notes

1. Remove the default event when dragging the mouse

Refer to my blog.

Javascript-cancel the default browser prompt when dragging an image

2. you can use math to control the Slider Area. max or marh. min 3. when using setinterval, pay attention to the difference between two different situations original effect address: http://js.fgm.cc/learn/iphone-unlock/ my demo download 2. you can use math to control the Slider Area. max or marh. min
Related Article

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.