Created
January 12, 2012 13:14
-
-
Save thokra/1600450 to your computer and use it in GitHub Desktop.
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).ready(function () { | |
$('#load_fade').fadeOut(1000); | |
var currOffset = 0; | |
var itemWidth = 976; | |
var entries = $(".entry"); | |
var numProjects = entries.length; | |
$(document).keydown(function (e) { | |
var current; | |
var keyCode = e.keyCode || e.which, | |
arrow = {left: 37, right: 39, up: 38, down: 40 }; | |
if(keyCode == 37 || keyCode == 39 || keyCode == 38 || keyCode == 40) { | |
var m = $(".entry:in-viewport") | |
if (m.length == 2) { | |
$.each(m, function (a) { | |
var l = $(window).scrollLeft(); | |
var w = $(window).width(); | |
if ($(this).offset().left + $(this).outerWidth() < l + w) { | |
current = $(this) | |
} | |
}); | |
} else { | |
var s = (m.length == 1) ? 0 : 1 | |
console.log("S:", s); | |
current = $(m[s]); | |
} | |
switch (keyCode) { | |
case arrow.left: | |
console.log("left: " + current); | |
var next = current.prev().prev(); | |
currOffset = currOffset - 1; | |
break; | |
case arrow.right: | |
console.log("right: " + current); | |
var next = current.next().next(); | |
currOffset = currOffset + 1; | |
break; | |
case arrow.up: | |
console.log("UP", current); | |
current.find(".slide_prev").click(); | |
break; | |
case arrow.down: | |
console.log("DOWN", current); | |
current.find(".slide_next").click(); | |
break; | |
} | |
if(currOffset < 0) currOffset = 0; | |
if(currOffset > numProjects-1) currOffset = numProjects; | |
console.log("currOffset: " + currOffset); | |
//$(window).scrollLeft(currOffset*itemWidth); | |
console.log(entries[currOffset]); | |
$(window).scrollTo( {top:$(window).scrollTop(), left:currOffset*itemWidth}, 300 ); | |
//$(entries[currOffset]).click(); | |
/* | |
if(next != undefined && next != null && next.hasClass('entry')) { | |
var bravo = ($(document).width()-$(window).width()) / (m.length-1) | |
var ents = $.makeArray($(".entry")) | |
//console.log("E: ", ents.indexOf(next[0])); | |
var s = bravo * ents.indexOf(next[0]); | |
//$(window).scrollLeft(Math.round(s)) | |
console.log("currOffset: " + currOffset); | |
$(window).scrollLeft(currOffset*itemWidth); | |
} | |
*/ | |
} | |
//return false; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment