Skip to content

Instantly share code, notes, and snippets.

@Tusko
Created May 11, 2016 13:53
Show Gist options
  • Select an option

  • Save Tusko/655a5f3618cd22a303bb91f4df297b25 to your computer and use it in GitHub Desktop.

Select an option

Save Tusko/655a5f3618cd22a303bb91f4df297b25 to your computer and use it in GitHub Desktop.
GAP Parallax
function exGAP(){
'use strict';
$('.is__gap').each(function(){
var t = $(this),
off = t.offset().top,
step = t.data('step'),
reverse = t.hasClass('__reverse') ? -1 : 1;
if( screen() >= off - screen('height')) {
t.css('background-position','50% '+ reverse * parseInt( ( screen() - off ) / (step || 4) , 10) + 'px');
}
});
}
$(window).scroll( exGAP );
<?php if($flex['photos']) {
echo '<div class="gap__wrap">';
foreach($flex['photos'] as $img){
echo '<div class="is__gap __reverse __gap100 __gap_fix" data-aload style="background-image: url(' . $img['url'] . ')"></div>';
}
echo '</div>';
} ?>
.is__gap {
@include background-size(cover);
background-repeat: no-repeat;
background-position: 50% 0;
position: relative;
&.__gap100 {
height: 100vh
}
&.__gap_fix {
background-attachment: fixed
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment