Skip to content

Instantly share code, notes, and snippets.

@gka

gka/script.js Secret

Created August 15, 2016 14:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gka/e9145b123d57511646093bec3102563c to your computer and use it in GitHub Desktop.
Save gka/e9145b123d57511646093bec3102563c to your computer and use it in GitHub Desktop.
horizontal scrolling
var scroll_pct = 0,
aspect_ratio = dimensions[0]/dimensions[1],
vw_height = $(window).height();
layoutDesktop();
window.onscroll = function() {
scroll_pct = window.scrollY / (document.body.scrollHeight - window.innerHeight);
$('.g-composite').css('left', '-' + (scroll_pct * (artboard_width - window.innerWidth)) + 'px');
};
window.onresize = _.throttle(layoutDesktop, 400);
function layoutDesktop() {
vw_height = $(window).height();
artboard_width = vw_height * aspect_ratio;
$(".g-composite").width(artboard_width);
$(".g-composite-wrapper").height(vw_height*aspect_ratio);
$('.g-composite').css('left', '-' + (scroll_pct * (artboard_width - window.innerWidth)) + 'px');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment