Sha256: ea62043c514ba6e1439bdf5486c982a14f08b8843b6f7362e42358850e26f7c0

Contents?: true

Size: 952 Bytes

Versions: 5

Compression:

Stored size: 952 Bytes

Contents

$(document).ready(function() {
  if ($("#js-parallax-window").length) {
    parallax();
  }
});

$(window).scroll(function(e) {
  if ($("#js-parallax-window").length) {
    parallax();
  }
});

function parallax(){
  if( $("#js-parallax-window").length > 0 ) {
    var plxBackground = $("#js-parallax-background");
    var plxWindow = $("#js-parallax-window");

    var plxWindowTopToPageTop = $(plxWindow).offset().top;
    var windowTopToPageTop = $(window).scrollTop();
    var plxWindowTopToWindowTop = plxWindowTopToPageTop - windowTopToPageTop;

    var plxBackgroundTopToPageTop = $(plxBackground).offset().top;
    var windowInnerHeight = window.innerHeight;
    var plxBackgroundTopToWindowTop = plxBackgroundTopToPageTop - windowTopToPageTop;
    var plxBackgroundTopToWindowBottom = windowInnerHeight - plxBackgroundTopToWindowTop;
    var plxSpeed = 0.35;

    plxBackground.css('top', - (plxWindowTopToWindowTop * plxSpeed) + 'px');
  }
}

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
refills-0.2.0 source/javascripts/refills/parallax.js
breezeblocks-0.0.4 source/javascripts/breezeblocks/parallax.js
breezeblocks-0.0.2 source/javascripts/breezeblocks/parallax.js
breezeblocks-0.0.1 source/javascripts/breezeblocks/parallax.js
refills-0.1.0 source/javascripts/refills/parallax.js