Home > Web Front-end > H5 Tutorial > body text

Xiaoqiang's HTML5 mobile development road (52) - touch interaction in jquerymobile

黄舟
Release: 2017-02-15 14:00:16
Original
1344 people have browsed it

When using mobile devices for touch operations, the most commonly used ones are tapping, pressing and holding the screen, or gesture operations. jQuery Mobile can respond to the user's specific touch behavior through bound touch events.

1. Tap and hold

to enter the code directly (everything is in the code, take a closer look!)


<!DOCTYPE html>
<html>
<head>
<title>练习</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, 
      initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" />
<link href="css/jquery.mobile-1.0.1.min.css" 
      rel="stylesheet" type="text/css"/>
<script src="js/jquery-1.6.4.js" 
      type="text/javascript" ></script>
<script src="js/jquery.mobile-1.0.1.js"  
      type="text/javascript" ></script>
<script type="text/javascript">
	$(&#39;#page1&#39;).live(&#39;tap&#39;, function(){
		$.mobile.changePage(&#39;#page2&#39;);
	});
	$(&#39;#page2&#39;).live(&#39;tap&#39;, function(){
		$.mobile.changePage(&#39;#page1&#39;);
	});
	$(&#39;#page1&#39;).live(&#39;taphold&#39;, function(){
		alert(&#39;taphold事件被触发&#39;);
	});
	$(&#39;#page2&#39;).live(&#39;taphold&#39;, function(){
		$.mobile.changePage(&#39;#about&#39;);
	});
</script>
</head>
<body>
	<section id="page1" data-role="page">
		<header data-role="header">
			<h1>Tap事件处理</h1>
		</header>
		<p class="content" data-role="content">
			轻击页面进入下一页<br/>
			按住不放,打开关于对话框
		</p>
		<footer data-role="footer"></footer>
	</section>	
	<section id="page2" data-role="page">
		<header data-role="header">
			<h1>Tap事件处理</h1>
		</header>
		<p class="content" data-role="content">
			轻击页面返回前一页
		</p>
		<footer data-role="footer">
		</footer>
	</section>
	<p id="abut" data-role="dialog">
		<p data-role="header">
			<h1>关于本程序</h1>
		</p>
		<p data-role="content">
			演示轻击触控事件响应
		</p>
	</p>
</body>
</html>
Copy after login

tap: tap event


taphold: hold event

2. Swipe

Swipe refers to writing with your finger or hand When the pen slides quickly left or right on the screen, the swipeleft event or swiperight event will be triggered.


<!DOCTYPE html>
<html>
<head>
<title>练习</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, 
      initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" />
<link href="css/jquery.mobile-1.0.1.min.css" 
      rel="stylesheet" type="text/css"/>
<script src="js/jquery-1.6.4.js" 
      type="text/javascript" ></script>
<script src="js/jquery.mobile-1.0.1.js"  
      type="text/javascript" ></script>
<script type="text/javascript">
	$(&#39;#page1&#39;).live(&#39;swiperight&#39;, function(){
		$.mobile.changePage(&#39;#page2&#39;);
	});
	$(&#39;#page2&#39;).live(&#39;swiperight&#39;, function(){
		$.mobile.changePage(&#39;#page1&#39;);
	});
	$(&#39;#page1&#39;).live(&#39;swipeleft&#39;, function(){
		$(&#39;#lnkDialog&#39;).click();
	});
	$(&#39;#page2&#39;).live(&#39;swiperleft&#39;, function(){
		$.mobile.changePage(&#39;#about&#39;);
	});
</script>
</head>
<body>
	<section id="page1" data-role="page">
		<header data-role="header">
			<h1>swipe事件处理</h1>
		</header>
		<p class="content" data-role="content">
			向右滑动页面进入下一页<br/>
			向左滑动页面,打开关于对话框
		</p>
		<footer data-role="footer"></footer>
	</section>	
	<section id="page2" data-role="page">
		<header data-role="header">
			<h1>swipe事件处理</h1>
		</header>
		<p class="content" data-role="content">
			向右滑动页面进入前一页br/>
			向左滑动页面,打开关于对话框
		</p>
		<footer data-role="footer">
		</footer>
	</section>
	<p id="abut" data-role="dialog">
		<p data-role="header">
			<h1>关于本程序</h1>
		</p>
		<p data-role="content">
			演示swipeleft&swiperight触控事件响应
		</p>
	</p>
	<a id="lnkDialog" href="#about" data-rel="dialog" data-transition="pop" style="display:none;"></a>
</body>
</html>
Copy after login

A trick is used in the above code. If you need to change the switching effect during the interface switching process, you must use a hyperlink to implement it. Set the display attribute of the link If it is none, call the click() method in the listening function to perform interface switching, and then add data-transition to the link to set the switching effect.


3. Virtual mouse event


##EventMeaningvmouseoverTouch or slide over the DOM containervmoseoutTouch Or slide away vmousedown touch or press vmoseupTouch off or mouse button ReleasevclickThe touch ends or the mouse button is releasedThe vclick event is usually in vmouseup Triggered 300ms after the eventvmousecancelTriggered when the mousecancel event is initiated in the touch event...... ..................
<!DOCTYPE html>
<html>
<head>
<title>练习</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, 
      initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" />
<link href="css/jquery.mobile-1.0.1.min.css" 
      rel="stylesheet" type="text/css"/>
<script src="js/jquery-1.6.4.js" 
      type="text/javascript" ></script>
<script src="js/jquery.mobile-1.0.1.js"  type="text/javascript" ></script>
<script type="text/javascript">
	$(&#39;#page1&#39;).live(&#39;vmouseup&#39;, function(event, ui){
		alert("当前点击位置" + "\n" +
			"\npageX:" + event.pageX +   //当前HTML页面横坐标
			"\npageY:" + event.pageY +   //当前HTML页面纵坐标
			"\nscreenX:" + event.screenX +  //当前屏幕横坐标
			"\nscreenY:" + event.screenY +  //当前屏幕纵坐标
			"\nclientX:" + event.clientX +  //当前窗口区域横坐标
			"\nclientY:" + event.clientY);  //当前窗口区域纵坐标
	});
</script>
</head>
<body>
	<section id="page1" data-role="page">
		<header data-role = "header">
			<h1>vMouse事件处理</h1>
		</header>
		<p class="content" data-role="content">
			轻击页面,显示点击位置
		</p>
		<p style="height: 500px;"></p>
		内容底部
		<footer data-role="footer"></footer>
	</section>
</body>
</html>
Copy after login
The above is the content of Xiaoqiang's HTML5 mobile development road (52) - touch interaction in jquerymobile. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!




source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!