Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.06 KB | None | 0 0
  1. /*
  2. * LucidScroll
  3. *
  4. * Created by Shikkediel (c) 2013-2019 ataredo.com
  5. *
  6. * Version 3.4
  7. *
  8. * Requires jQuery 1.8.0+
  9. * Includes easing equations
  10. *
  11. */
  12.  
  13. (function($, nub) {
  14.  
  15. $.fn.impulse = function(options) {
  16.  
  17. var set = $.extend(true, {}, $.fn.impulse.default, options), vessel = this,
  18. gate = $(nub), object = $(set.target), crux, area = {}, edge = [],
  19. fad = {}, entity, brink = [], outset = [], quit = [], kinetic, morph = [],
  20. hit, way, speed, destination = [], pour = 'requestAnimationFrame',
  21. use = $.extend({novel: pour in nub, turned: 0}, set);
  22.  
  23. elementAnalysis();
  24.  
  25. vessel.each(function(index) {
  26.  
  27. $(this).data('impulse', use).on('wheel.excite', function(act, info) {
  28.  
  29. if (!use.keen && !act.mien) return;
  30.  
  31. if (act.mien) {
  32. fad = $.extend({}, use, info);
  33. use.annul = fad.delay == true;
  34. var loom = act.mien;
  35. }
  36. else {
  37. if (use.annul) return;
  38. fad = use;
  39. loom = act.originalEvent.deltaY;
  40. }
  41.  
  42. loom = loom/Math.abs(loom);
  43. hit = index;
  44.  
  45. if (crux && vessel.length > 1) {
  46. entity = $(this);
  47. brink[0] = edge[hit];
  48. }
  49. else {
  50. entity = object;
  51. brink = edge;
  52. }
  53.  
  54. if (kinetic != loom || act.mien) use.turned = 1;
  55. else use.turned = Math.min(use.curb, use.turned+1);
  56.  
  57. if (typeof fad.range === 'function') fad.orbit = fad.range();
  58. else fad.orbit = fad.range;
  59.  
  60. if (!fad.delay && use.fluid && use.turned == 1) morph[hit] = 'curve';
  61. else if (use.turned) morph[hit] = fad.effect;
  62.  
  63. way = loom*fad.orbit*Math.pow(use.leap, use.turned-1);
  64. speed = fad.tempo*Math.pow(use.sloth, use.turned-1) || 1;
  65. kinetic = loom;
  66.  
  67. entity.each(function(part) {
  68. outset[part] = $(this).scrollTop();
  69. destination[part] = outset[part]+way;
  70. quit[part] = onFringe(this, part, outset[part]);
  71. });
  72.  
  73. use.waive = ceaseOperation();
  74.  
  75. if (!way) speed = 1;
  76. if (use.novel) {
  77. if (use.motion) {
  78. cancelAnimationFrame(use.motion);
  79. use.initial = use.present;
  80. }
  81. else use.initial = Date.now();
  82. use.motion = nub[pour](streamCore);
  83. }
  84. else inciteSource();
  85. });
  86.  
  87. this.addEventListener('wheel', function(tick) {
  88.  
  89. if (!use.keen) return;
  90. if (use.annul) return denyRise(tick);
  91. else if (fad.delay == true && !use.waive) use.annul = true;
  92. if (!(use.waive && use.occur)) denyRise(tick);
  93.  
  94. }, hasQuiet() ? {passive: false} : false);
  95. });
  96.  
  97. $.easing['curve'] = $.easing['easeInOutSine'];
  98.  
  99. gate.resize(function() {
  100. clearTimeout(use.bound);
  101. use.bound = setTimeout(detectOverflow, 100);
  102. });
  103.  
  104. return this;
  105.  
  106. function streamCore() {
  107. use.present = Date.now();
  108. var advance = Math.min(use.present-use.initial, speed)/speed,
  109. increase = $.easing[morph[hit]](advance);
  110. entity.each(function(key) {
  111. if (!quit[key]) {
  112. $(this).scrollTop(outset[key]+increase*way);
  113. checkLimits(this, key, advance);
  114. }
  115. });
  116. if (advance < 1 && !use.waive) use.motion = nub[pour](streamCore);
  117. else hindStage();
  118. }
  119.  
  120. function inciteSource() {
  121. entity.each(function(beat) {
  122. if (!quit[beat]) {
  123. $(this).stop().animate({scrollTop: destination[beat]}, {
  124. duration: speed,
  125. easing: morph[hit],
  126. progress: function(current, sequence) {
  127. checkLimits(this, beat, sequence);
  128. },
  129. complete: hindStage
  130. });
  131. }
  132. });
  133. }
  134.  
  135. function checkLimits(essence, rank, factor) {
  136. if (100*factor >= fad.reset) use.turned = 0;
  137. if (onFringe(essence, rank)) {
  138. quit[rank] = true;
  139. if (!use.novel) $(essence).stop(true, true);
  140. use.waive = ceaseOperation();
  141. }
  142. }
  143.  
  144. function onFringe(matter, cue, genesis) {
  145. var put = Math.round(genesis || $(matter).scrollTop()),
  146. above = destination[cue] < 0 && !put,
  147. below = destination[cue] > brink[cue] && put == brink[cue] && fad.orbit > 0;
  148. return above || below;
  149. }
  150.  
  151. function ceaseOperation() {
  152. return quit.every(function(flag) {return flag});
  153. }
  154.  
  155. function hindStage() {
  156. use.turned = use.annul = use.motion = 0;
  157. }
  158.  
  159. function denyRise(jab) {
  160. jab.preventDefault();
  161. jab.stopPropagation();
  162. }
  163.  
  164. function elementAnalysis() {
  165. var item = $();
  166. if (!object.length) {
  167. crux = true;
  168. object = vessel;
  169. }
  170. object.each(function() {
  171. if ($.zenith(this)) {
  172. if (!use.main) {
  173. if (use.novel) use.main = nub;
  174. else use.main = baseTag();
  175. item = item.add(use.main);
  176. }
  177. }
  178. else item = item.add(this);
  179. });
  180. use.target = object = item;
  181. object.each(function(zest) {
  182. if ($.zenith(this)) area[zest] = 'hub';
  183. else area[zest] = 'sub';
  184. });
  185. if (crux && use.main) vessel = object;
  186. detectOverflow();
  187. }
  188.  
  189. function baseTag() {
  190. var origin = gate.scrollTop();
  191. gate.scrollTop(1);
  192. if ($('html').scrollTop()) var root = 'html';
  193. else if ($('body').scrollTop()) root = 'body';
  194. else root = 'html, body';
  195. gate.scrollTop(origin);
  196. return root;
  197. }
  198.  
  199. function detectOverflow() {
  200. object.each(function(unit) {
  201. if (area[unit] == 'hub') var teem = $(document).height()-gate.height();
  202. else teem = this.scrollHeight-$(this).height();
  203. edge[unit] = Math.round(teem);
  204. });
  205. }
  206.  
  207. function hasQuiet() {
  208. var cold = false,
  209. hike = function() {};
  210. try {
  211. var aid = Object.defineProperty({}, 'passive', {
  212. get: function() {cold = true}
  213. });
  214. nub.addEventListener('test', hike, aid);
  215. nub.removeEventListener('test', hike, aid);
  216. } catch(e) {}
  217. return cold;
  218. }
  219. };
  220.  
  221. $.zenith = function(sample) {
  222.  
  223. var peak = [nub,document,'HTML','BODY'], facet;
  224. if (sample) return peak.indexOf(sample) > -1 || peak.indexOf(sample.tagName) > -1;
  225. $.each(peak, function(spot, detail) {
  226. facet = $(detail).data('impulse');
  227. if (facet) return false;
  228. });
  229. return facet;
  230. }
  231.  
  232. $.fn.impulse.default = {
  233.  
  234. target: '',
  235. range: 135,
  236. leap: 1.35,
  237. tempo: 500,
  238. sloth: 1.1,
  239. curb: 5,
  240. reset: 85,
  241. effect: 'easeOutSine',
  242. keen: true,
  243. delay: false,
  244. occur: true,
  245. fluid: true
  246. };
  247.  
  248. $.fn.demit = function() {
  249.  
  250. return this.each(function() {
  251. if ($.zenith(this)) var habit = $.zenith();
  252. else habit = $(this).data('impulse');
  253. if (habit) {
  254. if (habit.novel) cancelAnimationFrame(habit.motion);
  255. else habit.target.stop();
  256. habit.turned = habit.annul = habit.motion = 0;
  257. }
  258. });
  259. };
  260.  
  261. $.fn.amend = function(gist) {
  262.  
  263. return this.each(function() {
  264. if ($.zenith(this)) var quirk = $.zenith();
  265. else quirk = $(this).data('impulse');
  266. if (quirk) {
  267. $.each(gist, function(sign, rate) {
  268. if (sign in quirk) quirk[sign] = rate;
  269. });
  270. }
  271. });
  272. };
  273.  
  274. $.fn.evoke = function(unit) {
  275.  
  276. var zeal = $.Event('wheel.excite', {mien: true}), bulk;
  277. return this.each(function() {
  278. if ($.zenith(this)) {
  279. if (!bulk) {
  280. bulk = $.zenith();
  281. if (bulk) $(bulk.main).trigger(zeal, unit);
  282. }
  283. }
  284. else $(this).trigger(zeal, unit);
  285. });
  286. };
  287. }(jQuery, window));
  288.  
  289. /*
  290. * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS "AS IS" THROUGH OPEN SOURCE AND ANY
  291. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  292. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  293. * THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY OR
  294. * CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO PROCUREMENT OF SUBSTITUTE GOODS
  295. * OR SERVICES, LOSS OF USE, DATA, PROFITS OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  296. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  297. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  298. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  299. *
  300. */
  301.  
  302. // Based on easing equations from Robert Penner - robertpenner.com/easing
  303.  
  304. (function($){var b={};$.each(['Quad','Cubic','Quart','Quint','Expo'],function(i,n){b[n]=function(p){return Math.pow(p,i+2)}});$.extend(b,{Sine:function(p){return 1-Math.cos(p*Math.PI/2)},Circ:function(p){return 1-Math.sqrt(1-p*p)},Elastic:function(p){return p===0||p===1?p:-Math.pow(2,8*(p-1))*Math.sin(((p-1)*80-7.5)*Math.PI/15)},Back:function(p){return p*p*(3*p-2)},Bounce:function(p){var f,h=4;while(p<((f=Math.pow(2,--h))-1)/11){}return (1/Math.pow(4,3-h)-7.5625*Math.pow((f*3-2)/22-p,2))}});$.each(b,function(n,e){$.easing['easeIn'+n]=e;$.easing['easeOut'+n]=function(p){return 1-e(1-p)};$.easing['easeInOut'+n]=function(p){return p<0.5?e(p*2)/2:1-e(p*-2+2)/2}})})(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement