jQuery mobile swipe content only
Solution 1
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.
Solution 2
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/
Related videos on Youtube
Uffo
Updated on September 15, 2022Comments
-
Uffo over 1 year
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 withdata-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); } });
-
Uffo about 11 yearsYou the best give me a minute to test this out!
-
Uffo about 11 yearsThe only problem that I see on my iphone, when I swipe left, the text size decreases and increases like a snap...
-
Uffo about 11 yearsAnd it goes multiple slides foward... I guess I need an unbind..but I don't know how..
-
Gajotres about 11 yearsTry this one: jsfiddle.net/Gajotres/NV6Py , this should prevent multiple event binding. There are other method of multiple event binding prevention and you can find them in my other answer/article: stackoverflow.com/a/14469041/1848600
-
Uffo about 11 yearsIn order to prevent that
snap
to the right I needed<meta name="viewport" content="width=device-width, initial-scale=1"/>
works like a charm now, God bless you! I will accept it right now!