Skip to content

Commit

Permalink
Added jQuery Triggers when className changes so JS events can subscri…
Browse files Browse the repository at this point in the history
…be to this.

Added .each() before checkInViewport() so you can use className selectors and
not have all elements appear when the first match appears in the viewport
  • Loading branch information
unknown authored and unknown committed May 15, 2013
1 parent 6188e27 commit b9854ef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion js/divPeek.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ function recalcVars(){
scrollFromBottom = (parseInt(scrollFromTop)+parseInt(viewPortHeight));
for (var i = 0; i < elementsToTrack.length; i++) {
if ($(elementsToTrack[i]).exists()) {
checkInViewport(scrollFromBottom, elementsToTrack[i]);
$(elementsToTrack[i]).each(function () {
checkInViewport(scrollFromBottom, this);
})
}
}
}
Expand All @@ -41,7 +43,9 @@ function checkInViewport(scrollBottom, domElement){
var elementPos = $(domElement).offset().top;
if((parseInt(scrollBottom)+parseInt(pixelOffset)) > elementPos){
$(domElement).addClass(inClassName).removeClass(outClassName);
$(domElement).trigger(inClassName);
} else {
$(domElement).removeClass(inClassName).addClass(outClassName);
$(domElement).trigger(outClassName);
}
}
4 changes: 2 additions & 2 deletions js/divPeek.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var inClassName = "inViewPort";
var outClassName = "outViewPort";
//===============================================================================
jQuery.fn.exists=function(){return this.length>0;}
var viewPortHeight=$(window).height();var scrollFromTop=$(window).scrollTop();var scrollFromBottom=(parseInt(scrollFromTop)+parseInt(viewPortHeight));function recalcVars(){viewPortHeight=$(window).height();scrollFromTop=$(window).scrollTop();scrollFromBottom=(parseInt(scrollFromTop)+parseInt(viewPortHeight));for(var i=0;i<elementsToTrack.length;i++){if($(elementsToTrack[i]).exists()){checkInViewport(scrollFromBottom,elementsToTrack[i]);}}}
var viewPortHeight=$(window).height();var scrollFromTop=$(window).scrollTop();var scrollFromBottom=(parseInt(scrollFromTop)+parseInt(viewPortHeight));function recalcVars(){viewPortHeight=$(window).height();scrollFromTop=$(window).scrollTop();scrollFromBottom=(parseInt(scrollFromTop)+parseInt(viewPortHeight));for(var i=0;i<elementsToTrack.length;i++){if($(elementsToTrack[i]).exists()){$(elementsToTrack[i]).each(function () {checkInViewport(scrollFromBottom, this);})}}}
$(window).resize(function(e){recalcVars();});document.addEventListener("touchmove",ScrollStart,false);document.addEventListener("scroll",Scroll,false);function ScrollStart(){recalcVars();}
function Scroll(){recalcVars();}
function checkInViewport(scrollBottom,domElement){var elementPos=$(domElement).offset().top;if((parseInt(scrollBottom)+parseInt(pixelOffset))>elementPos){$(domElement).addClass(inClassName).removeClass(outClassName);}else{$(domElement).removeClass(inClassName).addClass(outClassName);}}
function checkInViewport(scrollBottom,domElement){var elementPos=$(domElement).offset().top;if((parseInt(scrollBottom)+parseInt(pixelOffset))>elementPos){$(domElement).addClass(inClassName).removeClass(outClassName);$(domElement).trigger(inClassName);}else{$(domElement).removeClass(inClassName).addClass(outClassName);$(domElement).trigger(outClassName);}}

0 comments on commit b9854ef

Please sign in to comment.