Skip to content

Instantly share code, notes, and snippets.

@sectsect
Created November 27, 2015 18:37
Show Gist options
  • Save sectsect/9777ae661d3b5a19fda5 to your computer and use it in GitHub Desktop.
Save sectsect/9777ae661d3b5a19fda5 to your computer and use it in GitHub Desktop.
inview.js
jQuery(function(){
var wrap = "#" + thisPanelId + ' .postcontent-inner';
var wrapHeight = jQuery(wrap).outerHeight(true);
var container = "#" + thisPanelId + ' .postcontent-box';
var target = "#" + thisPanelId + ' .postcontent-box .sec-post';
var offset = wrapHeight * 0.25; // 25% Height
jQuery(target).first().addClass("inview");
jQuery(target).each(function(){
var pTop = jQuery(this).position().top - wrapHeight + offset;
var pBtm = jQuery(this).position().top + jQuery(this).outerHeight(true) - offset;
var thisid = jQuery(this).attr("id");
jQuery(container).scroll(function(){
var y = jQuery(this).scrollTop();
if(y > pTop){
jQuery("#" + thisid).addClass("inview");
}
if(y < pTop || y > pBtm){
jQuery("#" + thisid).removeClass("inview");
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment