-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjQuery.keepInView.min.js
More file actions
1 lines (1 loc) · 909 Bytes
/
jQuery.keepInView.min.js
File metadata and controls
1 lines (1 loc) · 909 Bytes
1
(function(a){a.fn.scrollIntoView=function(b,c){var d={topLimit:0,scrollSpeed:500,scrollType:"swing"};b=a.extend(d,b);scrollTop=this.offset().top-b.topLimit;var e=function(){if(typeof c==="function"){c()}};if(a("html, body").scrollTop()!==scrollTop){a("html, body").animate({scrollTop:scrollTop},b.scrollSpeed,b.scrollType,e)}return this};a.fn.keepInView=function(b){var c,d={scrollSpeed:0},e=a(document).height(),f=this;b=a.extend(d,b);var g=function(){window.jQueryScrolling=true;f.scrollIntoView(b,function(){window.setTimeout(function(){window.jQueryScrolling=false},50)})};var h=function(){if(c){window.clearTimeout(c)}c=window.setTimeout(function(){var b=a(document).height();if(b!=e){e=b;g()}},500)};var i=function(){if(!window.jQueryScrolling){a(document).off("DOMSubtreeModified",h);a(window).off("scroll",i)}};a(window).on("scroll",i);a(document).on("DOMSubtreeModified",h);g();return this}})(jQuery)