<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