Skip to content

Instantly share code, notes, and snippets.

@ajayy004
Created July 14, 2016 10:54
Show Gist options
  • Save ajayy004/e1d17632ba5c9a7e8773e5aa61b63876 to your computer and use it in GitHub Desktop.
Save ajayy004/e1d17632ba5c9a7e8773e5aa61b63876 to your computer and use it in GitHub Desktop.
Jquery mobile swipe tab
<html>
<head>
<title>Swipe tab</title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-mobile/1.4.5/jquery.mobile.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-mobile/1.4.5/jquery.mobile.min.css">
</head>
<body>
<div data-role="page" id="lessonhomepage">
<!--content start-->
<div data-role="content" id="tabscontent">
<!--horizontal navigation tab start-->
<div data-role="tabs" id="tabs">
<div data-role="navbar" id="nav">
<ul>
<li><a class="ui-btn-active" href="#study" data-ajax="false">Study</a>
</li>
<li><a href="#quicktips" data-ajax="false">Quick Tips</a>
</li>
<li><a href="#testresults" data-ajax="false">Test Results</a>
</li>
</ul>
</div>
<div id="study">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
<div id="quicktips">
There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.
</div>
<div id="testresults">
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum
</div>
<!--horizontal navigation tab end-->
<br/>
</div>
</div>
</div>
<script type="text/javascript">
var panel = '<div data-theme="a" data-role="panel" data-display="overlay" id="leftpanel">sdf</div>';
$(function() {
$("body").prepend(panel);
$("[data-role=panel]").panel().enhanceWithin();
});
function changeNavTab(left) {
var $tabs = $("div[data-role=navbar] li a", $("div[data-role=page].ui-page-active"));
var curidx = $tabs.closest("a.ui-btn-active").parent().index();
var nextidx = 0;
if (left) {
nextidx = (curidx == $tabs.length - 1) ? 0 : curidx + 1;
} else {
nextidx = (curidx == 0) ? $tabs.length - 1 : curidx - 1;
}
$tabs.eq(nextidx).click();
}
$("div[data-role=content]").on("swipeleft", function(event) {
changeNavTab(true);
});
$("div[data-role=content]").on("swiperight", function(event) {
changeNavTab(false);
});
// Navigation Drawer Swipe Listener
$("div[data-role=header]").on("swipeleft swiperight", function(e) {
// save swipe direction right/left
var dir = 'prev';
if (e.type == 'swiperight') {
dir = 'next';
}
if (dir == 'prev') {
$('#leftpanel').panel('close');
} else {
$('#leftpanel').panel('open');
}
});
</script>
</body>
</html>
@RobertW-arboss
Copy link

Dude... you are the best. I looked at 12 different sites to find this simple task and they all had insanely overcomplicated solutions. This one page, <100 lines of code, written 4 YEARS AGO, solved what I was looking for. Thank you.

@ajayy004
Copy link
Author

@NoizTank thank you for the feedback, good to hear that it's helpful.

@namumakwembo
Copy link

namumakwembo commented Aug 10, 2021

OMG thank you very much , i spent the last two days looking for this code , you're an angel
can you please help me , i am having an issue when i try to add to code to my project

@ajayy004
Copy link
Author

OMG thank you very much , i spent the last two days looking for this code , you're an angel
can you please help me , i am having an issue when i try to add to code to my project

Thank you @theekingyodah what is the issue you're facing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment