-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnavigate.js
46 lines (38 loc) · 1.62 KB
/
navigate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* Navigate.js
*
* Copyright 2015, Shahabaz Khan (tigertooth01)
* Released under the MIT Licence
* http://opensource.org/licenses/MIT
*
* Github: https://github.com/tigertooth01/Navigate.js/
* Version: 1.0.1
*/
var _currentPage='';// initialize with first page's ID
var pageStack=[];//will contain the pages navigated
$(document).ready(function(){
$('.page').first().css('-webkit-transform', 'translate3d(0, 0, 0)');
_currentPage = '#'+$('.page').first().attr('id');//initialize with first page's ID.
pageStack.push(_currentPage);//pushing first page's ID to pageStack.
});
function navigateTo(page){
if(page!=_currentPage)
{
transLock = true;
pageStack.push(page);//add new page to page stack.
_currentPage = page;//set new page as current page.
$(_currentPage).css('-webkit-transform', 'translate3d(0, 0, 0)');//bring current page to front.
$(pageStack[pageStack.length-2]).css('-webkit-transform', 'translate3d(100%, 0, 0)');
//move previous page to right.
}
}
function navigateGoBack(){
if(pageStack.length>1)
{
transLock = true;
var poppedPage = pageStack.pop();//remove current page from page stack, and cache it.
_currentPage = pageStack[pageStack.length-1];//set current page as the last item in page stack ie. the previous page.
$(_currentPage).css('-webkit-transform', 'translate3d(0, 0, 0)');//bring current page to front.
$(poppedPage).css('-webkit-transform', 'translate3d(100%, 0, 0)');//move cached page to right.
}
}