-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathantigravity.min.js
3 lines (3 loc) · 1.02 KB
/
antigravity.min.js
1
2
3
// jQuery antiGravity Plugin v1.0
$.fn.isOnTheScreen=function(){var t=$(this).offset().top,n=t+$(this).outerHeight(),a=$(window).scrollTop(),r=a+$(window).height();return n>a&&t<r},$.fn.antiGravity=function(t){var n={};if(n.cutInHalf=!1,n.revert=-1,n.attenuation=5,n.duration=2e3,n.parent=jQuery(this).parent(),t){if(t.cutInHalf&&(n.cutInHalf=t.cutInHalf),t.attenuation&&5!=t.attenuation){if(isNaN(t.attenuation)||!(t.attenuation>0))throw new Error("antiGravity says: attenuation is not a number or is smaller than zero");n.attenuation=t.attenuation}0==t.revert&&(n.revert=1),t.duration&&t.duration>0&&(n.duration=t.duration),t.parent&&$(t.parent).length>0&&(n.parent=$(t.parent))}jQuery(this).css("transition","all "+n.duration+"ms");var a=this;$(window).on("scroll",function(){if($(a).isOnTheScreen()){var t=$(window).scrollTop(),r=n.parent.position().top;n.cutInHalf?t<=r&&$(a).css("transform","translateY("+t/n.attenuation*n.revert+"px)"):$(a).css("transform","translateY("+t/n.attenuation*n.revert+"px)")}})};