Created
February 15, 2012 15:36
-
-
Save omgmog/1836735 to your computer and use it in GitHub Desktop.
Specific case for breaking up page in to slides that slide in/out of viewport.
This file contains 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(){ | |
$("section.page").hide(); | |
var hash = window.location.hash; | |
if(hash){ | |
$('a[href$="'+hash+'"]').parent().addClass('active').siblings('li.active').removeClass("active"); | |
$('section'+hash).show(); | |
console.log(hash); | |
check_for_dark($('section'+hash)); | |
}else{ | |
$("section#splash").show(); | |
} | |
$("#mainheader").on('click','ul a',function(e){ | |
e.preventDefault(); | |
var $target = $($(this).attr("href")); | |
if(!$target.is(':visible')){ | |
$vpwidth = $(window).width(); | |
$twidth = $target.width(); | |
$moffset = ($vpwidth-$twidth)/2; | |
$('html,body').css({'overflow-x':'hidden'}); | |
$('.page:visible').animate({'position':'absolute','margin-left':-980, 'opacity':0},200,function(){ | |
// +position, +margin-left | |
$(this).hide(); | |
$(this).css({'margin-left':'','margin-right':-980, 'right':0}); | |
// -margin-left, +margin-right | |
$target | |
.css({'position':'absolute','margin-left':'','margin-right':-980, 'right':0, 'opacity':0}) | |
.show() | |
.animate({'margin-right':'','right':$moffset,'display':'block', 'opacity':1},200,function(){ | |
$(this).removeAttr("style").css({'display':'block'}); | |
$target.siblings('.page').hide(); | |
$('html,body').removeAttr("style"); | |
check_for_dark($target); | |
}); | |
}); | |
$(this).parent('li').addClass("active").siblings('li.active').removeClass("active"); | |
} | |
}); | |
}); | |
function check_for_dark($target){ | |
if($target.index()%2===0){ | |
$("html").addClass("dark"); | |
}else{ | |
$("html").removeClass("dark"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment