Created
April 4, 2012 16:11
-
-
Save tpryan/2303369 to your computer and use it in GitHub Desktop.
Page Slide Without a Framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body{ | |
position: relative; | |
-webkit-transition: left .2s ease; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener('DOMContentLoaded', function() { | |
replaceLinks(); | |
}); | |
function replaceLinks(){ | |
var links = document.querySelectorAll('a'); | |
for (i=0; i<links.length; i++){ | |
var link = links[i]; | |
link.addEventListener("click",replacePage, false); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
event.preventDefault(); | |
var href= this.href; | |
var ajax = new XMLHttpRequest(); | |
ajax.open("GET",href,true); | |
ajax.send(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body.style.left = "-100%"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body.addEventListener( 'webkitTransitionEnd', moveToRight, false); | |
function moveToRight(event){ | |
var body = document.querySelector('body'); | |
body.removeEventListener( 'webkitTransitionEnd', moveToRight, false); | |
body.addEventListener( 'webkitTransitionEnd', returnToCenter, false); | |
body.style.opacity = 0; | |
body.style.left = "100%" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function returnToCenter(event){ | |
var body = document.querySelector('body'); | |
body.removeEventListener( 'webkitTransitionEnd', returnToCenter, false); | |
body.innerHTML = bodyContent; | |
history.pushState(null, null, href); | |
body.style.opacity = 1; | |
body.style.left = 0; | |
replaceLinks(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.addEventListener("popstate", handleBackButton); | |
function handleBackButton(e) { | |
var ajaxBack = new XMLHttpRequest(); | |
ajaxBack.open("GET",location.pathname,true); | |
ajaxBack.send(); | |
ajaxBack.onreadystatechange=function(){ | |
var bodyBack = document.querySelector('body'); | |
var bodyBackContent = grabBody(ajaxBack.responseText, "body"); | |
bodyBack.addEventListener( 'webkitTransitionEnd', moveToLeft, false); | |
bodyBack.style.left = "100%"; | |
function backToCenter(event){ | |
var body = document.querySelector('body'); | |
body.removeEventListener( 'webkitTransitionEnd', backToCenter, false); | |
body.innerHTML = bodyBackContent; | |
body.style.opacity = 1; | |
body.style.left = 0; | |
replaceLinks(); | |
} | |
function moveToLeft(event){ | |
var body = document.querySelector('body'); | |
body.removeEventListener( 'webkitTransitionEnd', moveToLeft, false); | |
body.addEventListener( 'webkitTransitionEnd', backToCenter, false); | |
body.style.opacity = 0; | |
body.style.left = "-100%" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment