Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use touch event to realize the effect of sliding up and down pages in html5

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "how to use touch events in html5 to achieve the effect of sliding up and down pages". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The html5 touch event realizes the effect of sliding up and down the page.

2014-4-29

* {margin: 0; padding: 0;}

# outer {width:90%; height: 490px; background: # 000; margin: auto; overflow: hidden;}

# inner {width:80%; height: 2000px; background: # f67d42; margin: auto; position:relative; top:0;}

one hundred and twenty three

one hundred and twenty three

Gag

Af

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

Yryyr

Ryry

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

Sdff

Fef

one hundred and twenty three

Hr

Hrh

5y

one hundred and twenty three

Er

Ert

one hundred and twenty three

Rgdgdg

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

Gfgfgfgfgfgf

Sdsdsdsdsdsd

Sf

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

Gdggdgdg

one hundred and twenty three

Drgdrgd

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

Yuyuyuyuyuy

Hjkhjkhkhkhjkhkh

Kjkjk

one hundred and twenty three

one hundred and twenty three

Gag

Af

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

Yryyr

Ryry

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

Sdff

Fef

one hundred and twenty three

Hr

Hrh

5y

one hundred and twenty three

Er

Ert

one hundred and twenty three

Rgdgdg

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

Gfgfgfgfgfgf

Sdsdsdsdsdsd

Sf

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

Gdggdgdg

one hundred and twenty three

Drgdrgd

one hundred and twenty three

one hundred and twenty three

one hundred and twenty three

Yuyuyuyuyuy

Hjkhjkhkhkhjkhkh

Kjkjk

Coordinates when var startX,// touches

StartY

X, / / sliding distance

Y

AboveY=0; / / set a global variable to record the position of the last internal block slide

Var inner=document.getElementById ("inner")

Function touchSatrt (e) {/ / Touch

E.preventDefault ()

Var touch=e.touches [0]

StartY = touch.pageY; / / coordinates at the time of touch

}

Function touchMove (e) {/ / Slide

E.preventDefault ()

Var touch = e.touches [0]

Y = touch.pageY-startY;// sliding distance

/ / inner.style.webkitTransform = 'translate (' + 0 +'px,'+ y +'px)'; / / you can also use css3

Inner.style.top=aboveY+y+ "px"; / / in this sentence

}

Function touchEnd (e) {/ / fingers off the screen

E.preventDefault ()

AboveY=parseInt (inner.style.top); / / record the sliding position of the internal slider at the end of touch. It is reflected in the global variable that it must be converted to an integer number with parseInt ().

} / /

Document.getElementById ("outer") .addEventListener ('touchstart', touchSatrt,false)

Document.getElementById ("outer") .addEventListener ('touchmove', touchMove,false)

Document.getElementById ("outer") .addEventListener ('touchend', touchEnd,false)

This is the end of the content of "how to use the touch event in html5 to achieve the effect of swiping up and down the page". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report