-
Notifications
You must be signed in to change notification settings - Fork 139
/
jquery.interactive_3d.min.js
1 lines (1 loc) · 4.19 KB
/
jquery.interactive_3d.min.js
1
!function(e){function n(e){var t=e.changedTouches[0];var n=document.createEvent("MouseEvent");n.initMouseEvent({touchstart:"mousedown",touchmove:"mousemove",touchend:"mouseup"}[e.type],true,true,window,1,t.screenX,t.screenY,t.clientX,t.clientY,false,false,false,false,0,null);t.target.dispatchEvent(n)}var t={frames:10,cursor:"move",speed:0,entrance:true,preloadImages:true,touchSupport:true,loading:"Loading..",autoPlay:false};e.fn.preload=function(t){e("<div class='images_cache'></div>").hide().appendTo(t);this.each(function(){e("<img/>").attr("src",this).appendTo(".images_cache")})};e.fn.drags=function(t){var n=this;return n.css("cursor",t.cursor).on("mousedown",function(r){var i=e(this).addClass("draggable"),s=r.pageX,o={};i.parents().on("mousemove",function(r){if(e(".draggable").length>0){var i=n.find("img.main-frame").attr("src"),s=i.split("/")[i.split("/").length-1],u=s.split("_")[1].split(".")[0];if(typeof o.x!="undefined"){var a=o.x-r.clientX,f=o.y-r.clientY;if(Math.abs(a)>Math.abs(f)&&a>0){if(u>1){setTimeout(function(){var e=i.split("/")[i.split("/").length-1];var t=i.split("/").slice(0,-1).join("/");var r=t+"/"+e.split("_")[0]+"_"+(parseInt(u)-1)+"."+e.split(".")[1];n.find("img.main-frame").attr("src",r)},t.speed)}else{setTimeout(function(){var e=i.split("/")[i.split("/").length-1];var r=i.split("/").slice(0,-1).join("/");var s=r+"/"+e.split("_")[0]+"_"+parseInt(t.frames)+"."+e.split(".")[1];n.find("img.main-frame").attr("src",s)},t.speed)}}else if(Math.abs(a)>Math.abs(f)&&a<0){if(u<t.frames){setTimeout(function(){var e=i.split("/")[i.split("/").length-1];var t=i.split("/").slice(0,-1).join("/");var r=t+"/"+e.split("_")[0]+"_"+(parseInt(u)+1)+"."+e.split(".")[1];n.find("img.main-frame").attr("src",r)},t.speed)}else{setTimeout(function(){var e=i.split("/")[i.split("/").length-1];var t=i.split("/").slice(0,-1).join("/");var r=t+"/"+e.split("_")[0]+"_"+1+"."+e.split(".")[1];n.find("img.main-frame").attr("src",r)},t.speed)}}}o={x:r.clientX,y:r.clientY}}e(".draggable").on("mouseup",function(){e(this).removeClass("draggable")})});r.preventDefault()}).on("mouseup",function(){e(this).removeClass("draggable")})};e.fn.interactive_3d=function(r){function o(){var e=s.find("img.main-frame").attr("src");s.find("img.main-frame").css("opacity",x*step/100);if(cur_frame<i.frames){setTimeout(function(){var t=e.split("/")[e.split("/").length-1];var n=e.split("/").slice(0,-1).join("/");var r=n+"/"+t.split("_")[0]+"_"+(parseInt(cur_frame)+1)+"."+t.split(".")[1];s.find("img.main-frame").attr("src",r);cur_frame=parseInt(cur_frame)+1},i.speed)}else{setTimeout(function(){var t=e.split("/")[e.split("/").length-1];var n=e.split("/").slice(0,-1).join("/");var r=n+"/"+t.split("_")[0]+"_"+1+"."+t.split(".")[1];s.find("img.main-frame").attr("src",r);cur_frame=1},i.speed)}if(x++<i.frames-1){if(i.autoPlay!=false){setTimeout(o,0)}else{setTimeout(o,x*1.5)}}}var i=e.extend({},t,r),s=e(this);s.find(" > img").addClass("main-frame");s.drags(i),x=0,step=100/parseInt(i.frames),cur_frame=s.find("img.main-frame").attr("src").split("_")[1].split(".")[0];if(i.entrance==true&&i.autoPlay==false){if(i.loading==false&&i.autoPlay==false)o()}if(i.touchSupport==true){document.addEventListener("touchstart",n,true);document.addEventListener("touchmove",n,true);document.addEventListener("touchend",n,true);document.addEventListener("touchcancel",n,true)}if(i.preloadImages==true){var u=s.find("img.main-frame").attr("src");arr=[];for(var a=1;a<i.frames+1;a++){var f=u.split("/")[u.split("/").length-1];var l=u.split("/").slice(0,-1).join("/");arr.push(l+"/"+f.split("_")[0]+"_"+a+"."+f.split(".")[1])}e(arr).preload(s);if(i.loading!=false){var c=e(".images_cache > img").not(function(){return this.complete});var h=c.length;s.append("<div class='loading_3d'>"+i.loading+"</div>");s.find(".main-frame").css("visibility","hidden");if(h){c.load(function(){h--;if(!h){s.find(".main-frame").css("visibility","visible");s.find(".loading_3d").remove();if(i.autoPlay==false)o()}})}else{s.find(".main-frame").css("visibility","visible");s.find(".loading_3d").remove();if(i.autoPlay==false)o()}}}if(i.autoPlay!=false){function p(){return window.setInterval(function(){o()},i.autoPlay)}var d=p();s.mouseenter(function(){window.clearInterval(d)}).mouseleave(function(){d=p()})}}}(window.jQuery)