forked from peachananr/tiltedpage_scroll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.tiltedpage-scroll.min.js
1 lines (1 loc) · 1.5 KB
/
jquery.tiltedpage-scroll.min.js
1
!function(e){var t={sectionContainer:"> section",angle:50,opacity:true,scale:true,outAnimation:true};e.fn.tiltedpage_scroll=function(n){function s(t){var n=e(window).scrollTop(),r=n+e(window).height(),i=t.offset().top,s=i+t.outerHeight(true);return s>=n&&i<=r}function o(e){if(s(e)){e.addClass("tps-inview")}else{e.removeClass("tps-inview")}}var r=e.extend({},t,n),i=e(this);i.find(r.sectionContainer).addClass("tps-section");i.find(".tps-section").each(function(){var t=e(this);t.wrapInner("<div class='tps-wrapper'></div>")});e(window).on("DOMContentLoaded load resize scroll",function(){i.find(r.sectionContainer).each(function(){o(e(this))});i.find(".tps-section.tps-inview > .tps-wrapper").each(function(t){var n=e(this),i=0,s=e(window).scrollTop(),o=(n.parent().offset().top-n.parent().height()-s)/e(window).height()*r.angle*3,u=(s+e(window).height()-(n.parent().offset().top-n.parent().height()))/e(window).height();if(u>1)u=1;if(o<0)o=0;if(s>n.parent().offset().top){if(r.outAnimation==false){i=1;if(i<0)i=0;if(o<0)o=0}else{i=(n.parent().offset().top+e(window).height()*1.2-s)/e(window).height();i=Math.pow(i,25);o=(n.parent().offset().top-s)/e(window).height()*r.angle*3;u=(s+e(window).height()-n.parent().offset().top)/e(window).height()}}else{if(t!=0){var i=(s+e(window).height()-n.parent().offset().top+n.height()/2)/e(window).height();if(i>1){i=1}}else{i=1;o=0;u=1}}if(r.scale==false)u=1;if(r.angle==false)o=0;if(r.opacity==false)i=1;n.css({transform:"rotateX("+o+"deg) scale("+u+", "+u+")",opacity:i})})})}}(window.jQuery)