我在 stackoverflow 上搜索以查找在我的应用程序之间滑动的代码,我找到了下面的 jquery 代码。从我读到的答案中,它工作正常,但是当我把它放在我的页面上时,它无法工作。
Javascript:
$('div.ui-page').live("swipeleft", function () {
var nextpage = $(this).next('div[data-role="page"]');
if (nextpage.length > 0) {
$.mobile.changePage(nextpage, "slide", false, true);
}
});
$('div.ui-page').live("swiperight", function () {
var prevpage = $(this).prev('div[data-role="page"]');
if (prevpage.length > 0) {
$.mobile.changePage(prevpage, {
transition: "slide",
reverse: true
}, true, true);
}
});
HTML:
<div data-role="page" id="news">
<div data-role="header" data-position="fixed" data-tap-toggle="false" data-theme="b">
<h1>Current Affairs</h1>
<a href='source.html' class='ui-btn-left' data-icon="home">Home</a>
<a href='#' class='ui-btn-right' data-icon='arrow-l' onclick="history.back(); return false">Back</a>
</div>
<div id="news_feed" data-role="content" data-theme="e">Loading Headlines, Please Wait</div>
<div id="tv_links" data-position="fixed" data-tap-toggle="false" data-role="footer" data-theme="b">
<div data-role="navbar">
<ul>
<li><a href="#business" data-role="button" data-inline="true" data-icon="info">Business News </a>
<li><a href="#sportsnews" data-role="button" data-inline="true" data-icon="info">Sports News </a>
<li>
<a href="#weather_update" data-role="button" data-inline="true" data-icon="info">Weather </a>
<li>
<a href="#interactive" data-role="button" data-inline="true" data-icon="info">Get Live </a>
</ul>
</div>
</div>
</div>
<p>
<div data-role="page" id="business">
<div data-role="header" data-theme="b">
<h1>Business News</h1>
<a href='source.html' class='ui-btn-left' data-icon="home">Home</a>
<a href='#' class='ui-btn-right' data-icon='arrow-l' onclick="history.back(); return false">Back</a>
</div>
<div id="biz" data-role="content" data-theme="e">Loading Headlines, Please Wait</div>
<div id="tv_links" data-position="fixed" data-role="footer" data-theme="b">
<div data-role="navbar">
<ul>
<li><a href="#business" data-role="button" data-inline="true" data-icon="info">Business News </a>
<li><a href="#sportsnews" data-role="button" data-inline="true" data-icon="info">Sports News </a>
<li>
<a href="#weather_update" data-role="button" data-inline="true" data-icon="info">Weather </a>
<li>
<a href="#interactive" data-role="button" data-inline="true" data-icon="info">Get Live </a>
</ul>
</div>
</div>
</div>
</p>
<p>
<div data-role="page" id="politics">
<div data-role="header" data-theme="b">
<h1>Politics</h1>
<a href='source.html' class='ui-btn-left' data-icon="home">Home</a>
<a href='#' class='ui-btn-right' data-icon='arrow-l' onclick="history.back(); return false">Back</a>
</div>
<div id="polit" data-role="content" data-theme="e">Loading Headlines, Please Wait</div>
<div id="tv_links" data-position="fixed" data-role="footer" data-theme="b">
<div data-role="navbar">
<ul>
<li><a href="#business" data-role="button" data-inline="true" data-icon="info">Business News </a>
<li><a href="#sportsnews" data-role="button" data-inline="true" data-icon="info">Sports News </a>
<li>
<a href="#weather_update" data-role="button" data-inline="true" data-icon="info">Weather </a>
<li>
<a href="#interactive" data-role="button" data-inline="true" data-icon="info">Get Live </a>
</ul>
</div>
</div>
</div>
</p>
<p>
<div data-role="page" id="sportsnews">
<div data-role="header" data-theme="b">
<h1>Sports News</h1>
<a href='source.html' class='ui-btn-left' data-icon="home">Home</a>
<a href='#' class='ui-btn-right' data-icon='arrow-l' onclick="history.back(); return false">Back</a>
</div>
<div id="sports" data-role="content" data-theme="e">Loading Headlines, Please Wait</div>
<div id="tv_links" data-position="fixed" data-role="footer" data-theme="b">
<div data-role="navbar">
<ul>
<li><a href="#business" data-role="button" data-inline="true" data-icon="info">Business News </a>
<li><a href="#sportsnews" data-role="button" data-inline="true" data-icon="info">Sports News </a>
<li>
<a href="#weather_update" data-role="button" data-inline="true" data-icon="info">Weather </a>
<li>
<a href="#interactive" data-role="button" data-inline="true" data-icon="info">Get Live </a>
</ul>
</div>
</div>
</div>
</p>
<p>
<div data-role="page" id="business_news">
<div data-role="header" data-theme="b">
<h1>Business News</h1>
<a href='source.html' class='ui-btn-left' data-icon="home">Home</a>
<a href='#' class='ui-btn-right' data-icon='arrow-l' onclick="history.back(); return false">Back</a>
</div>
<div data-role="content" data-theme="e">Loading Headlines, Please Wait</div>
<div id="tv_links" data-position="fixed" data-role="footer" data-theme="b">
<div data-role="navbar">
<ul>
<li><a href="#" data-role="button" data-inline="true" data-icon="info">Business News </a>
<li><a href="#sportsnews" data-role="button" data-inline="true" data-icon="info">Sports News </a>
<li>
<a href="#weather_update" data-role="button" data-inline="true" data-icon="info">Weather </a>
<li>
<a href="#interactive" data-role="button" data-inline="true" data-icon="info">Get Live </a>
</ul>
</div>
</div>
</div>
</p>
<p>
<div id="interactive" data-role="page" data-theme="d" data-position="fixed">
<div data-role="header" data-theme="b">
<h1>Get Interactive</h1>
<a href='source.html' class='ui-btn-left' data-icon="home">Home</a>
<a href='#' class='ui-btn-right' data-icon='arrow-l' onclick="history.back(); return false">Back</a>
</div>
<div data-role="content" data-theme="e">
<div data-role="collapsible-set">
<div id="morning_show" data-role="collapsible" data-theme="d">
<h3>Morning Show</h3>
<script language="javascript">
$.post('quest_rev.asp', $('#form1').serialize(), function () {
// Do something
});
</script>
<h3> </h3>
</div>
<div data-collapsed="true" data-role="collapsible" data-theme="d">
<h3>E- News</h3>
<p> </p>
</div>
<div data-collapsed="true" data-role="collapsible" data-theme="d">
<h3>Political Programme</h3>
<p> </p>
</div>
</div>
</div>
<div id="tv_links" data-position="fixed" data-role="footer" data-theme="b">
<div data-role="navbar">
<ul>
<li><a href="#business" data-role="button" data-inline="true" data-icon="info">Business News </a>
<li><a href="#sportsnews" data-role="button" data-inline="true" data-icon="info">Sports News </a>
<li>
<a href="#weather_update" data-role="button" data-inline="true" data-icon="info">Weather </a>
<li>
<a href="#interactive" data-role="button" data-inline="true" data-icon="info">Get Live </a>
</ul>
</div>
</div>
</div>
</p>
<div data-role="page" id="weather_update">
<div data-role="header" data-theme="b">
<h1>Weather Update</h1>
<a href='source.html' class='ui-btn-left' data-icon="home">Home</a>
<a href='#' class='ui-btn-right' data-icon='arrow-l' onclick="history.back(); return false">Back</a>
</div>
<div id="weather" data-role="content" data-theme="e">Getting Updates, Please Wait</div>
<div id="tv_links" data-position="fixed" data-role="footer" data-theme="b">
<div data-role="navbar">
<ul>
<li><a href="#" data-role="button" data-inline="true" data-icon="info">Business News </a>
<li><a href="#sportsnews" data-role="button" data-inline="true" data-icon="info">Sports News </a>
<li>
<a href="#weather_update" data-role="button" data-inline="true" data-icon="info">Weather </a>
<li>
<a href="#interactive" data-role="button" data-inline="true" data-icon="info">Get Live </a>
</ul>
</div>
</div>
</div>