diff --git a/bower.json b/bower.json index c4840c2..df1c54e 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "jquery-smoove", "description": "A simple jQuery plugin for sexy scrolling effects using CSS3 transitions and transforms.", - "version": "0.2.10", + "version": "0.2.11", "main": "dist/jquery.smoove.js", "homepage": "http://smoove.js.org/", "authors": [ diff --git a/dist/jquery.smoove.js b/dist/jquery.smoove.js index 58927eb..5633b36 100644 --- a/dist/jquery.smoove.js +++ b/dist/jquery.smoove.js @@ -1,5 +1,5 @@ /*! -* jQuery Smoove v0.2.10 (http://smoove.js.org/) +* jQuery Smoove v0.2.11 (http://smoove.js.org/) * Copyright (c) 2017 Adam Bouqdib * Licensed under GPL-2.0 (http://abemedia.co.uk/license) */ @@ -84,6 +84,27 @@ } } + function throttle(fn, threshhold, scope) { + threshhold = threshhold || 250; + var last, deferTimer; + return function() { + var context = scope || this, + now = +new Date(), + args = arguments; + if (last && now < last + threshhold) { + // hold on to it + clearTimeout(deferTimer); + deferTimer = setTimeout(function() { + last = now; + fn.apply(context, args); + }, threshhold); + } else { + last = now; + fn.apply(context, args); + } + }; + } + $.fn.smoove = function(options) { $.fn.smoove.init(this, $.extend({}, $.fn.smoove.defaults, options)); return this; @@ -121,8 +142,7 @@ if (!$.fn.smoove.loaded) { $.fn.smoove.loaded = true; - var didScroll = false, - oldScroll = 0, + var oldScroll = 0, oldHeight = $(window).height(), oldWidth = $(window).width(), oldDocHeight = $(document).height(), @@ -133,7 +153,7 @@ $('body').css('overflow-x', 'hidden'); } - $(window).resize(function() { + $(window).on("orientationchange resize", function() { clearTimeout(resizing); resizing = setTimeout(function() { var height = $(window).height(), @@ -173,18 +193,12 @@ smooveIt(); // throttle scroll handler - $(window).scroll(function() { - didScroll = true; - }); - setInterval(function() { - if (didScroll) { - didScroll = false; - var scrolltop = $(window).scrollTop(), - direction = (scrolltop < oldScroll) ? direction = 'up' : 'down'; - oldScroll = scrolltop; - smooveIt(direction); - } - }, 250); + $(window).on('scroll', throttle(function() { + var scrolltop = $(window).scrollTop(), + direction = (scrolltop < oldScroll) ? direction = 'up' : 'down'; + oldScroll = scrolltop; + smooveIt(direction); + }, 250)); }); } }; diff --git a/dist/jquery.smoove.min.js b/dist/jquery.smoove.min.js index bfb956a..0991ab2 100644 --- a/dist/jquery.smoove.min.js +++ b/dist/jquery.smoove.min.js @@ -1,8 +1,8 @@ /*! -* jQuery Smoove v0.2.10 (http://smoove.js.org/) +* jQuery Smoove v0.2.11 (http://smoove.js.org/) * Copyright (c) 2017 Adam Bouqdib * Licensed under GPL-2.0 (http://abemedia.co.uk/license) */ -!function(a,b,c){function d(a,b,c){function d(a){return a.charAt(0).toUpperCase()+a.slice(1)}for(var e=["webkit","moz","ms","o"],f={},g=0;gf||i.min_height>e)return!1;var j=!c||"down"===c&&"1"===h.css("opacity")?0:i.offset,k=a(b).scrollTop()+e-h.data("top");if("string"==typeof j&&j.indexOf("%")&&(j=parseInt(j)/100*e),kf?h="up":"down",i=a.fn.smoove.items;if(k=f,l!==g){for(var j=0;jf||i.min_height>e)return!1;var j=!c||"down"===c&&"1"===h.css("opacity")?0:i.offset,k=a(b).scrollTop()+e-h.data("top");if("string"==typeof j&&j.indexOf("%")&&(j=parseInt(j)/100*e),kf?h="up":"down",i=a.fn.smoove.items;if(k=f,l!==g){for(var j=0;j