Skip to content

Instantly share code, notes, and snippets.

@danielthall
Last active January 4, 2016 17:59
Show Gist options
  • Save danielthall/8657359 to your computer and use it in GitHub Desktop.
Save danielthall/8657359 to your computer and use it in GitHub Desktop.
$window = $(window);
$('section[data-type="background"]').each(function() {
var $scroll = $(this);
$(window).scroll(function() {
var xPos = -($window.scrollTop() / $scroll.data('speed'));
var coords = xPos + 'px ' + 'bottom';
$scroll.css({ backgroundPosition: coords });
});
});
$('[data-direction="top"]').each(function() {
var $scroll = $(this);
$(window).scroll(function() {
var yPos = -($window.scrollTop() / $scroll.data('speed'));
$scroll.css("top", yPos + 'px');
});
});
$('[data-direction="right"]').each(function() {
var $scroll = $(this);
$(window).scroll(function() {
var xPos = -($window.scrollTop() / $scroll.data('speed'));
$scroll.css("left", -xPos + 'px');
});
});
$('[data-direction="left"]').each(function() {
var $scroll = $(this);
$(window).scroll(function() {
var xPos = -($window.scrollTop() / $scroll.data('speed'));
$scroll.css("left", xPos + 'px');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment