Skip to content

Instantly share code, notes, and snippets.

@d8uv
Created April 9, 2010 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d8uv/361566 to your computer and use it in GitHub Desktop.
Save d8uv/361566 to your computer and use it in GitHub Desktop.
"use strict";
$(document).ready(function () {
var slidepos, winwidth, LEFT, RIGHT;
slidepos = 0;
winwidth = $(window).width();
LEFT = -1;
RIGHT = 1;
//Initial Positioning
$("body > div").each(function () {
$(this).show();
$(this).offset({left: slidepos});
slidepos += winwidth;
});
slidepos = 0;
function moveSlider(direction) {
slidepos += direction * winwidth;
if (slidepos < 0) {
slidepos = 0;
}
if (slidepos > $(document).width() - winwidth) {
slidepos = $(document).width() - winwidth;
}
$(window).scrollLeft(slidepos);
}
$(window).click(function() {
moveSlider(RIGHT);
});
$(window).keydown(function (e) {
if (e.keyCode === 37) {
moveSlider(LEFT);
}
else if (e.keyCode === 39) {
moveSlider(RIGHT);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment