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

1 line
1.2 KiB
JavaScript

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