PageRenderTime 57ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/assets/layout/unify-v1.9.1/Blog-Magazine/assets/plugins/revolution-slider/revolution/js/extensions/source/revolution.extension.parallax.js

https://gitlab.com/augustocbx/grimes
JavaScript | 227 lines | 159 code | 55 blank | 13 comment | 41 complexity | 2bad8b9c0bbfa01261efd8a5d61fdc0b MD5 | raw file
  1. /********************************************
  2. * REVOLUTION 5.0 EXTENSION - PARALLAX
  3. * @version: 1.0.1 (17.08.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. checkForParallax : function(container,opt) {
  12. var _ = opt.parallax;
  13. if (_ISM && _.disable_onmobile=="on") return false;
  14. opt.li.each(function() {
  15. var li = jQuery(this);
  16. for (var i = 1; i<=10;i++)
  17. li.find('.rs-parallaxlevel-'+i).each(function() {
  18. var pw = jQuery(this),
  19. tpw = pw.closest('.tp-parallax-wrap');
  20. tpw.data('parallaxlevel',_.levels[i-1])
  21. tpw.addClass("tp-parallax-container");
  22. });
  23. })
  24. if (_.type=="mouse" || _.type=="scroll+mouse" || _.type=="mouse+scroll") {
  25. container.mouseenter(function(event) {
  26. var currslide = container.find('.active-revslide');
  27. var t = container.offset().top,
  28. l = container.offset().left,
  29. ex = (event.pageX-l),
  30. ey = (event.pageY-t);
  31. currslide.data("enterx",ex);
  32. currslide.data("entery",ey);
  33. })
  34. container.on('mousemove.hoverdir, mouseleave.hoverdir',function(event) {
  35. var currslide = container.find('.active-revslide');
  36. switch (event.type) {
  37. case "mousemove":
  38. if (_.origo=="enterpoint") {
  39. var t = container.offset().top,
  40. l = container.offset().left;
  41. if (currslide.data("enterx") ==undefined) currslide.data("enterx",(event.pageX-l));
  42. if (currslide.data("entery") ==undefined) currslide.data("entery",(event.pageY-t));
  43. var mh = currslide.data("enterx"),
  44. mv = currslide.data("entery"),
  45. diffh = (mh - (event.pageX - l)),
  46. diffv = (mv - (event.pageY - t)),
  47. s = _.speed/1000 || 0.4;
  48. } else {
  49. var t = container.offset().top,
  50. l = container.offset().left,
  51. diffh = (opt.conw/2 - (event.pageX-l)),
  52. diffv = (opt.conh/2 - (event.pageY-t)),
  53. s = _.speed/1000 || 3;
  54. }
  55. currslide.find(".tp-parallax-container").each(function() {
  56. var pc = jQuery(this),
  57. pl = parseInt(pc.data('parallaxlevel'),0)/100,
  58. offsh = diffh * pl,
  59. offsv = diffv * pl;
  60. if (_.type=="scroll+mouse" || _.type=="mouse+scroll")
  61. punchgs.TweenLite.to(pc,s,{force3D:"auto",x:offsh,ease:punchgs.Power3.easeOut,overwrite:"all"});
  62. else
  63. punchgs.TweenLite.to(pc,s,{force3D:"auto",x:offsh,y:offsv,ease:punchgs.Power3.easeOut,overwrite:"all"});
  64. })
  65. break;
  66. case "mouseleave":
  67. currslide.find(".tp-parallax-container").each(function() {
  68. var pc = jQuery(this);
  69. if (_.type=="scroll+mouse" || _.type=="mouse+scroll")
  70. punchgs.TweenLite.to(pc,1.5,{force3D:"auto",x:0,ease:punchgs.Power3.easeOut});
  71. else
  72. punchgs.TweenLite.to(pc,1.5,{force3D:"auto",x:0,y:0,ease:punchgs.Power3.easeOut});
  73. })
  74. break;
  75. }
  76. });
  77. if (_ISM)
  78. window.ondeviceorientation = function(event) {
  79. var y = Math.round(event.beta || 0),
  80. x = Math.round(event.gamma || 0);
  81. var currslide = container.find('.active-revslide');
  82. if (jQuery(window).width() > jQuery(window).height()){
  83. var xx = x;
  84. x = y;
  85. y = xx;
  86. }
  87. var curh = 360/container.width() * x,
  88. curv = 180/container.height() * y;
  89. currslide.find(".tp-parallax-container").each(function() {
  90. var pc = jQuery(this),
  91. pl = parseInt(pc.data('parallaxlevel'),0)/100,
  92. offsh = curh * pl,
  93. offsv = curv * pl;
  94. punchgs.TweenLite.to(pc,0.2,{force3D:"auto",x:offsh,y:offsv,ease:punchgs.Power3.easeOut});
  95. })
  96. }
  97. }
  98. /*if (_.type=="scroll" || _.type=="scroll+mouse" || _.type=="mouse+scroll")
  99. if (_ISM && opt.parallax.disable_onmobile=="on")
  100. return false;
  101. else*/
  102. _R.scrollTicker(opt,container);
  103. },
  104. scrollTicker : function(opt,container) {
  105. if (opt.scrollTicker!=true) {
  106. opt.scrollTicker = true;
  107. punchgs.TweenLite.ticker.fps(150);
  108. punchgs.TweenLite.ticker.addEventListener("tick",function() {_R.scrollHandling(opt);},container,true,1);
  109. }
  110. },
  111. // - SET POST OF SCROLL PARALLAX -
  112. scrollHandling : function(opt) {
  113. opt.lastwindowheight = opt.lastwindowheight || jQuery(window).height();
  114. var t = opt.c.offset().top,
  115. st = jQuery(window).scrollTop(),
  116. b = new Object(),
  117. _v = opt.viewPort,
  118. _ = opt.parallax;
  119. if (opt.lastscrolltop==st) return false;
  120. opt.lastscrolltop = st;
  121. b.top = (t-st);
  122. b.h = opt.conh==0 ? opt.c.height() : opt.conh;
  123. b.bottom = (t-st) + b.h;
  124. var proc = b.top<0 ? b.top / b.h : b.bottom>opt.lastwindowheight ? (b.bottom-opt.lastwindowheight) / b.h : 0;
  125. opt.scrollproc = proc;
  126. if (_R.callBackHandling)
  127. _R.callBackHandling(opt,"parallax","start");
  128. var area = 1-Math.abs(proc);
  129. area = area<0 ? 0 : area;
  130. if (_v.enable) {
  131. if (1-_v.visible_area<=area) {
  132. if (!opt.inviewport) {
  133. opt.inviewport = true;
  134. _R.enterInViewPort(opt);
  135. }
  136. } else {
  137. if (opt.inviewport) {
  138. opt.inviewport = false;
  139. _R.leaveViewPort(opt);
  140. }
  141. }
  142. }
  143. // SCROLL BASED PARALLAX EFFECT
  144. if (_ISM && opt.parallax.disable_onmobile=="on") return false;
  145. var pt = new punchgs.TimelineLite();
  146. pt.pause();
  147. if (_.type=="scroll" || _.type=="scroll+mouse" || _.type=="mouse+scroll")
  148. opt.c.find(".tp-parallax-container").each(function(i) {
  149. var pc = jQuery(this),
  150. pl = parseInt(pc.data('parallaxlevel'),0)/100,
  151. offsv = proc * -(pl*opt.conh);
  152. pc.data('parallaxoffset',offsv);
  153. pt.add(punchgs.TweenLite.set(pc,{force3D:"auto",y:offsv}),0);
  154. });
  155. opt.c.find('.tp-revslider-slidesli .slotholder, .tp-revslider-slidesli .rs-background-video-layer').each(function() {
  156. var t = jQuery(this),
  157. l = t.data('bgparallax') || opt.parallax.bgparallax;
  158. l = l == "on" ? 1 : l;
  159. if (l!== undefined || l !== "off") {
  160. var pl = opt.parallax.levels[parseInt(l,0)-1]/100,
  161. offsv = proc * -(pl*opt.conh);
  162. if (jQuery.isNumeric(offsv))
  163. pt.add(punchgs.TweenLite.set(t,{position:"absolute",top:"0px",left:"0px",backfaceVisibility:"hidden",force3D:"true",y:offsv+"px",overwrite:"auto"}),0);
  164. }
  165. });
  166. if (_R.callBackHandling)
  167. _R.callBackHandling(opt,"parallax","end");
  168. pt.play(0);
  169. }
  170. });
  171. //// END OF PARALLAX EFFECT
  172. })(jQuery);