Reputation: 10046
So I used the jquery mobile ui to do a page, swipe left/right, now this dosen't work for me since I just want to swipe only the content, not the entery body of the page, I tried to use data-role="content"
but It doesn't work anymore only with data-role="page"
is it posibile to have that swipe animation, but only for the content?
I have some <article>
and I want to swipe them left/right....but I don't want to swipe the header and other things..just the middle section.
And also to disable that stupid jquery mobile theme if posibile.
//Le
Code structure
<header data-role="header"> .... </header>
<section>
<!-- only this part I want to swipe, one article at a time -->
<article data-role="page"> ..... </article>
<article data-role="page"> ..... </article>
<article data-role="page"> ..... </article>
<article data-role="page"> ..... </article>
<!-- only this part I want to swipe, one article at a time -->
</section>
<footer> ... </footer>
$('article').bind("swipeleft", function(){
var nextpage = $(this).next('article[data-role="page"]');
// swipe using id of next page if exists
if (nextpage.length > 0) {
$.mobile.changePage(nextpage, {transition: "slide",
reverse: false}, true, true);
}
});
$('article').bind("swiperight", function(){
var prevpage = $(this).prev('article[data-role="page"]');
if (prevpage.length > 0) {
$.mobile.changePage(prevpage, {transition: "slide",
reverse: true}, true, true);
}
});
Upvotes: 4
Views: 17388
Reputation: 1248
Another method is to pin your fixed headers/footers in their position and then slide will move content only.
HTML:
<body>
<div id="site-header"> My fixed-position header </div>
<div data-role="page" id="pageone">
...
<a href="#pagetwo" data-transition="slide">Slide to Page Two</a>
...
</div>
<div data-role="page" id="pagetwo">
...
<a href="#pageone">Go to Page One</a>
...
</div>
</body>
CSS:
#site-header {
position: absolute;
top: 0px;
left: 0px;
width: 100%;
z-index: 1;
}
See also: http://www.artandlogic.com/blog/2013/11/jquery-mobile-transitions-static-vs-dynamic-content-part-ii/
Upvotes: 1
Reputation: 57309
You can cheat here, there's a way you can change page in jQM but make it look like only content has been changed. It can be done if you place a data-id="footer" attribute in every header and every footer.
I have created a working jsFiddle example for you: http://jsfiddle.net/Gajotres/NV6Py/
<!DOCTYPE html>
<html>
<head>
<title>Share QR</title>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
</head>
<body>
<article data-role="page" id="article1">
<div data-role="header" data-theme="b" data-position="fixed" data-id="footer">
<h1>Articles</h1>
</div>
<div data-role="content">
<p>Article 1</p>
</div>
<div data-role="footer" data-theme="b" data-position="fixed" data-id="footer">
<h1>Footer</h1>
</div>
</article>
<article data-role="page" id="article2">
<div data-role="header" data-theme="b" data-position="fixed" data-id="footer">
<a href="#article1" data-icon="home" data-iconpos="notext">Home</a>
<h1>Articles</h1>
</div>
<div data-role="content">
<p>Article 2</p>
</div>
<div data-role="footer" data-theme="b" data-position="fixed" data-id="footer">
<h1>Footer</h1>
</div>
</article>
<article data-role="page" id="article3">
<div data-role="header" data-theme="b" data-position="fixed" data-id="footer">
<a href="#article1" data-icon="home" data-iconpos="notext">Home</a>
<h1>Articles</h1>
</div>
<div data-role="content">
<p>Article 3</p>
</div>
<div data-role="footer" data-theme="b" data-position="fixed" data-id="footer">
<h1>Footer</h1>
</div>
</article>
</body>
</html>
In case you want to prevent jQM page styling you can do it with a help of a data-enhance="false" attribute, it must be placed in page/article container and initialized with a :
<script>
$(document).on('mobileinit', function () {
$.mobile.ignoreContentEnabled = true;
});
</script>
Also remember, mobileinit event must be initialized before jQM js is loaded.
I have also a working example of this : http://jsfiddle.net/Gajotres/5gXKj/, this is a same example like top one but without jQM page markup enhancement.
Upvotes: 11