yavsc/Yavsc/wwwroot/js/parallax.min.js

1 line
1.2 KiB
JavaScript

$(document).ready(function(o){var u=o(window),p=o(window).width(),b=o(window).height(),a=function(t,r,e){var n=t.data("speed"),o=(u.scrollLeft()+r-p/2)/n,a=(u.scrollTop()+e-b/2)/n,g=t.attr("orgbgpx")-Math.round(o),s=t.attr("orgbgpy")-Math.round(a),i=""+g+t.attr("orgbgpxu")+s+t.attr("orgbgpyu");t.css({backgroundPosition:i})},g=0,s=0;o('[data-type="background"]').each(function(){var r=o(this),t=r.css("backgroundPosition").split(" "),e=t[0],n=t[1];/%$/.test(e)?(e=e.substr(0,e.length-1),r.attr("orgbgpxu","% ")):/em$/.test(e)?(e=e.substr(0,e.length-2),r.attr("orgbgpxu","em ")):(/px$/.test(e)&&(e=e.substr(0,e.length-2)),r.attr("orgbgpxu","px ")),/%$/.test(n)?(n=n.substr(0,n.length-1),r.attr("orgbgpyu","% ")):/em$/.test(n)?(n=n.substr(0,n.length-2),r.attr("orgbgpyu","em ")):(/px$/.test(n)&&(n=n.substr(0,n.length-2)),r.attr("orgbgpyu","px ")),r.attr("orgbgpx",parseInt(e)),r.attr("orgbgpy",parseInt(n)),o(window).scroll(function(){a(r,g,s)}),window.DeviceOrientationEvent&&(320<p&&320<b&&window.addEventListener("deviceorientation",function(t){g=p*Math.sin(t.gamma*Math.PI/180),s=b*Math.sin(t.beta*Math.PI/90),a(r,g,s)},!1),o(window).mousemove(function(t){g=t.pageX,s=t.pageY,a(r,t.pageX,t.pageY)}))})}(jQuery));