revolution.extension.parallax.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. /********************************************
  2. * REVOLUTION 5.0 EXTENSION - PARALLAX
  3. * @version: 1.0.5 (20.10.2015)
  4. * @requires jquery.themepunch.revolution.js
  5. * @author ThemePunch
  6. *********************************************/
  7. (function($) {
  8. var _R = jQuery.fn.revolution,
  9. _ISM = _R.is_mobile();
  10. jQuery.extend(true,_R, {
  11. /*callStaticDDDParallax: function(container,opt,li) {
  12. // STATIC 3D PARALLAX MOVEMENTS
  13. if (opt.parallax && (opt.parallax.ddd_path=="static" || opt.parallax.ddd_path=="both")) {
  14. var coo = {},
  15. path = li.data('3dpath');
  16. coo.li = li;
  17. if (path.split(',').length>1) {
  18. coo.h = parseInt(path.split(',')[0],0);
  19. coo.v = parseInt(path.split(',')[1],0);
  20. container.trigger('trigger3dpath',coo);
  21. }
  22. }
  23. },*/
  24. checkForParallax : function(container,opt) {
  25. var _ = opt.parallax;
  26. if (_ISM && _.disable_onmobile=="on") return false;
  27. if (_.type=="3D" || _.type=="3d") {
  28. punchgs.TweenLite.set(opt.c,{overflow:_.ddd_overflow});
  29. punchgs.TweenLite.set(opt.ul,{overflow:_.ddd_overflow});
  30. if (opt.sliderType!="carousel" && _.ddd_shadow=="on") {
  31. opt.c.prepend('<div class="dddwrappershadow"></div>')
  32. punchgs.TweenLite.set(opt.c.find('.dddwrappershadow'),{force3D:"auto",transformPerspective:1600,transformOrigin:"50% 50%", width:"100%",height:"100%",position:"absolute",top:0,left:0,zIndex:0});
  33. }
  34. }
  35. opt.li.each(function() {
  36. var li = jQuery(this);
  37. if (_.type=="3D" || _.type=="3d") {
  38. li.find('.slotholder').wrapAll('<div class="dddwrapper" style="width:100%;height:100%;position:absolute;top:0px;left:0px;overflow:hidden"></div>');
  39. li.find('.tp-parallax-wrap').wrapAll('<div class="dddwrapper-layer" style="width:100%;height:100%;position:absolute;top:0px;left:0px;z-index:5;overflow:'+_.ddd_layer_overflow+';"></div>');
  40. // MOVE THE REMOVED 3D LAYERS OUT OF THE PARALLAX GROUP
  41. li.find('.rs-parallaxlevel-tobggroup').closest('.tp-parallax-wrap').wrapAll('<div class="dddwrapper-layertobggroup" style="position:absolute;top:0px;left:0px;z-index:50;width:100%;height:100%"></div>');
  42. var dddw = li.find('.dddwrapper'),
  43. dddwl = li.find('.dddwrapper-layer'),
  44. dddwlbg = li.find('.dddwrapper-layertobggroup');
  45. dddwlbg.appendTo(dddw);
  46. if (opt.sliderType=="carousel") {
  47. if (_.ddd_shadow=="on") dddw.addClass("dddwrappershadow");
  48. punchgs.TweenLite.set(dddw,{borderRadius:opt.carousel.border_radius});
  49. }
  50. punchgs.TweenLite.set(li,{overflow:"visible",transformStyle:"preserve-3d",perspective:1600});
  51. punchgs.TweenLite.set(dddw,{force3D:"auto",transformOrigin:"50% 50%"});
  52. punchgs.TweenLite.set(dddwl,{force3D:"auto",transformOrigin:"50% 50%",zIndex:5});
  53. punchgs.TweenLite.set(opt.ul,{transformStyle:"preserve-3d",transformPerspective:1600});
  54. }
  55. for (var i = 1; i<=_.levels.length;i++)
  56. li.find('.rs-parallaxlevel-'+i).each(function() {
  57. var pw = jQuery(this),
  58. tpw = pw.closest('.tp-parallax-wrap');
  59. tpw.data('parallaxlevel',_.levels[i-1])
  60. tpw.addClass("tp-parallax-container");
  61. });
  62. })
  63. if (_.type=="mouse" || _.type=="scroll+mouse" || _.type=="mouse+scroll" || _.type=="3D" || _.type=="3d") {
  64. container.mouseenter(function(event) {
  65. var currslide = container.find('.active-revslide'),
  66. t = container.offset().top,
  67. l = container.offset().left,
  68. ex = (event.pageX-l),
  69. ey = (event.pageY-t);
  70. currslide.data("enterx",ex);
  71. currslide.data("entery",ey);
  72. });
  73. container.on('mousemove.hoverdir, mouseleave.hoverdir, trigger3dpath',function(event,data) {
  74. var currslide = data && data.li ? data.li : container.find('.active-revslide');
  75. // CALCULATE DISTANCES
  76. if (_.origo=="enterpoint") {
  77. var t = container.offset().top,
  78. l = container.offset().left;
  79. if (currslide.data("enterx")==undefined) currslide.data("enterx",(event.pageX-l));
  80. if (currslide.data("entery")==undefined) currslide.data("entery",(event.pageY-t));
  81. var mh = currslide.data("enterx") || (event.pageX-l),
  82. mv = currslide.data("entery") || (event.pageY-t),
  83. diffh = (mh - (event.pageX - l)),
  84. diffv = (mv - (event.pageY - t)),
  85. s = _.speed/1000 || 0.4;
  86. } else {
  87. var t = container.offset().top,
  88. l = container.offset().left,
  89. diffh = (opt.conw/2 - (event.pageX-l)),
  90. diffv = (opt.conh/2 - (event.pageY-t)),
  91. s = _.speed/1000 || 3;
  92. }
  93. /*if (event.type=="trigger3dpath") {
  94. diffh = data.h;
  95. diffv = data.v;
  96. _.ddd_lasth = diffh;
  97. _.ddd_lastv = diffv;
  98. }*/
  99. if (event.type=="mouseleave") {
  100. diffh = _.ddd_lasth || 0;
  101. diffv = _.ddd_lastv || 0;
  102. s = 1.5;
  103. }
  104. /*if (_.ddd_path=="static") {
  105. diffh = _.ddd_lasth || 0;
  106. diffv = _.ddd_lastv || 0;
  107. }*/
  108. currslide.find(".tp-parallax-container").each(function() {
  109. var pc = jQuery(this),
  110. bl = parseInt(pc.data('parallaxlevel'),0),
  111. pl = _.type=="3D" || _.type=="3d" ? bl/200 : bl/100,
  112. offsh = diffh * pl,
  113. offsv = diffv * pl;
  114. if (_.type=="scroll+mouse" || _.type=="mouse+scroll" )
  115. punchgs.TweenLite.to(pc,s,{force3D:"auto",x:offsh,ease:punchgs.Power3.easeOut,overwrite:"all"});
  116. else
  117. punchgs.TweenLite.to(pc,s,{force3D:"auto",x:offsh,y:offsv,ease:punchgs.Power3.easeOut,overwrite:"all"});
  118. });
  119. if (_.type=="3D" || _.type=="3d") {
  120. var sctor = '.tp-revslider-slidesli .dddwrapper, .dddwrappershadow, .tp-revslider-slidesli .dddwrapper-layer';
  121. if (opt.sliderType==="carousel") sctor = ".tp-revslider-slidesli .dddwrapper, .tp-revslider-slidesli .dddwrapper-layer";
  122. opt.c.find(sctor).each(function() {
  123. var t = jQuery(this),
  124. pl = _.levels[_.levels.length-1]/200,
  125. offsh = diffh * pl,
  126. offsv = diffv * pl,
  127. offrv = opt.conw == 0 ? 0 : Math.round((diffh / opt.conw * pl)*100) || 0,
  128. offrh = opt.conh == 0 ? 0 : Math.round((diffv / opt.conh * pl)*100) || 0,
  129. li = t.closest('li'),
  130. zz = 0,
  131. itslayer = false;
  132. if (t.hasClass("dddwrapper-layer")) {
  133. zz = _.ddd_z_correction || 65;
  134. itslayer = true;
  135. }
  136. if (t.hasClass("dddwrapper-layer")) {
  137. offsh=0;
  138. offsv=0;
  139. }
  140. if (li.hasClass("active-revslide") || opt.sliderType!="carousel")
  141. if (_.ddd_bgfreeze!="on" || (itslayer))
  142. punchgs.TweenLite.to(t,s,{rotationX:offrh, rotationY:-offrv, x:offsh, z:zz,y:offsv,ease:punchgs.Power3.easeOut,overwrite:"all"});
  143. else
  144. punchgs.TweenLite.to(t,0.5,{force3D:"auto",rotationY:0, rotationX:0, z:0,ease:punchgs.Power3.easeOut,overwrite:"all"});
  145. else
  146. punchgs.TweenLite.to(t,0.5,{force3D:"auto",rotationY:0,z:0,x:0,y:0, rotationX:0, z:0,ease:punchgs.Power3.easeOut,overwrite:"all"});
  147. if (event.type=="mouseleave")
  148. punchgs.TweenLite.to(jQuery(this),3.8,{z:0, ease:punchgs.Power3.easeOut});
  149. });
  150. }
  151. });
  152. if (_ISM)
  153. window.ondeviceorientation = function(event) {
  154. var y = Math.round(event.beta || 0)-70,
  155. x = Math.round(event.gamma || 0);
  156. var currslide = container.find('.active-revslide');
  157. if (jQuery(window).width() > jQuery(window).height()){
  158. var xx = x;
  159. x = y;
  160. y = xx;
  161. }
  162. var cw = container.width(),
  163. ch = container.height(),
  164. diffh = (360/cw * x),
  165. diffv = (180/ch * y),
  166. s = _.speed/1000 || 3;
  167. currslide.find(".tp-parallax-container").each(function() {
  168. var pc = jQuery(this),
  169. bl = parseInt(pc.data('parallaxlevel'),0),
  170. pl = bl/100,
  171. offsh = diffh * pl*2,
  172. offsv = diffv * pl*4;
  173. punchgs.TweenLite.to(pc,s,{force3D:"auto",x:offsh,y:offsv,ease:punchgs.Power3.easeOut,overwrite:"all"});
  174. });
  175. if (_.type=="3D" || _.type=="3d") {
  176. var sctor = '.tp-revslider-slidesli .dddwrapper, .dddwrappershadow, .tp-revslider-slidesli .dddwrapper-layer';
  177. if (opt.sliderType==="carousel") sctor = ".tp-revslider-slidesli .dddwrapper, .tp-revslider-slidesli .dddwrapper-layer";
  178. opt.c.find(sctor).each(function() {
  179. var t = jQuery(this),
  180. pl = _.levels[_.levels.length-1]/200
  181. offsh = diffh * pl,
  182. offsv = diffv * pl*3,
  183. offrv = opt.conw == 0 ? 0 : Math.round((diffh / opt.conw * pl)*500) || 0,
  184. offrh = opt.conh == 0 ? 0 : Math.round((diffv / opt.conh * pl)*700) || 0,
  185. li = t.closest('li'),
  186. zz = 0,
  187. itslayer = false;
  188. if (t.hasClass("dddwrapper-layer")) {
  189. zz = _.ddd_z_correction || 65;
  190. itslayer = true;
  191. }
  192. if (t.hasClass("dddwrapper-layer")) {
  193. offsh=0;
  194. offsv=0;
  195. }
  196. if (li.hasClass("active-revslide") || opt.sliderType!="carousel")
  197. if (_.ddd_bgfreeze!="on" || (itslayer))
  198. punchgs.TweenLite.to(t,s,{rotationX:offrh, rotationY:-offrv, x:offsh, z:zz,y:offsv,ease:punchgs.Power3.easeOut,overwrite:"all"});
  199. else
  200. punchgs.TweenLite.to(t,0.5,{force3D:"auto",rotationY:0, rotationX:0, z:0,ease:punchgs.Power3.easeOut,overwrite:"all"});
  201. else
  202. punchgs.TweenLite.to(t,0.5,{force3D:"auto",rotationY:0,z:0,x:0,y:0, rotationX:0, z:0,ease:punchgs.Power3.easeOut,overwrite:"all"});
  203. if (event.type=="mouseleave")
  204. punchgs.TweenLite.to(jQuery(this),3.8,{z:0, ease:punchgs.Power3.easeOut});
  205. });
  206. }
  207. }
  208. }
  209. _R.scrollTicker(opt,container);
  210. },
  211. scrollTicker : function(opt,container) {
  212. if (opt.scrollTicker!=true) {
  213. opt.scrollTicker = true;
  214. punchgs.TweenLite.ticker.fps(150);
  215. punchgs.TweenLite.ticker.addEventListener("tick",function() {_R.scrollHandling(opt);},container,true,1);
  216. }
  217. },
  218. // - SET POST OF SCROLL PARALLAX -
  219. scrollHandling : function(opt) {
  220. opt.lastwindowheight = opt.lastwindowheight || jQuery(window).height();
  221. var t = opt.c.offset().top,
  222. st = jQuery(window).scrollTop(),
  223. b = new Object(),
  224. _v = opt.viewPort,
  225. _ = opt.parallax;
  226. if (opt.lastscrolltop==st) return false;
  227. opt.lastscrolltop = st;
  228. b.top = (t-st);
  229. b.h = opt.conh==0 ? opt.c.height() : opt.conh;
  230. b.bottom = (t-st) + b.h;
  231. var proc = b.top<0 ? b.top / b.h : b.bottom>opt.lastwindowheight ? (b.bottom-opt.lastwindowheight) / b.h : 0;
  232. opt.scrollproc = proc;
  233. if (_R.callBackHandling)
  234. _R.callBackHandling(opt,"parallax","start");
  235. var area = 1-Math.abs(proc);
  236. area = area<0 ? 0 : area;
  237. if (_v.enable) {
  238. if (1-_v.visible_area<=area) {
  239. if (!opt.inviewport) {
  240. opt.inviewport = true;
  241. _R.enterInViewPort(opt);
  242. }
  243. } else {
  244. if (opt.inviewport) {
  245. opt.inviewport = false;
  246. _R.leaveViewPort(opt);
  247. }
  248. }
  249. }
  250. // SCROLL BASED PARALLAX EFFECT
  251. if (_ISM && opt.parallax.disable_onmobile=="on") return false;
  252. var pt = new punchgs.TimelineLite();
  253. pt.pause();
  254. if (_.type!="3d" && _.type!="3D") {
  255. if (_.type=="scroll" || _.type=="scroll+mouse" || _.type=="mouse+scroll")
  256. opt.c.find(".tp-parallax-container").each(function(i) {
  257. var pc = jQuery(this),
  258. pl = parseInt(pc.data('parallaxlevel'),0)/100,
  259. offsv = proc * -(pl*opt.conh);
  260. pc.data('parallaxoffset',offsv);
  261. pt.add(punchgs.TweenLite.set(pc,{force3D:"auto",y:offsv}),0);
  262. });
  263. opt.c.find('.tp-revslider-slidesli .slotholder, .tp-revslider-slidesli .rs-background-video-layer').each(function() {
  264. var t = jQuery(this),
  265. l = t.data('bgparallax') || opt.parallax.bgparallax;
  266. l = l == "on" ? 1 : l;
  267. if (l!== undefined || l !== "off") {
  268. var pl = opt.parallax.levels[parseInt(l,0)-1]/100,
  269. offsv = proc * -(pl*opt.conh);
  270. if (jQuery.isNumeric(offsv))
  271. pt.add(punchgs.TweenLite.set(t,{position:"absolute",top:"0px",left:"0px",backfaceVisibility:"hidden",force3D:"true",y:offsv+"px",overwrite:"auto"}),0);
  272. }
  273. });
  274. }
  275. if (_R.callBackHandling)
  276. _R.callBackHandling(opt,"parallax","end");
  277. pt.play(0);
  278. }
  279. });
  280. //// END OF PARALLAX EFFECT
  281. })(jQuery);