From 3814132af4f261704344a311726ec10452a0cb65 Mon Sep 17 00:00:00 2001 From: Yura Griga Date: Tue, 16 Jun 2015 21:27:52 +0300 Subject: [PATCH 1/2] prevent smoothscroll if Ctrl or Cmd key is pressed --- lib/jquery.simplr.smoothscroll.js | 21 ++++++++++++--------- lib/jquery.simplr.smoothscroll.min.js | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/jquery.simplr.smoothscroll.js b/lib/jquery.simplr.smoothscroll.js index 6dc60bf..266804b 100644 --- a/lib/jquery.simplr.smoothscroll.js +++ b/lib/jquery.simplr.smoothscroll.js @@ -36,19 +36,22 @@ // events self.target.mousewheel(function (event, delta) { - wheel = true + if( !event.ctrlKey && !event.metaKey){ - if (delta < 0) // down - top = (top+viewport) >= self.target.outerHeight(true) ? top : top+=step + wheel = true - else // up - top = top <= 0 ? 0 : top-=step + if (delta < 0) // down + top = (top+viewport) >= self.target.outerHeight(true) ? top : top+=step - target.stop().animate({scrollTop: top}, self.speed, self.ease, function () { - wheel = false - }) + else // up + top = top <= 0 ? 0 : top-=step + + target.stop().animate({scrollTop: top}, self.speed, self.ease, function () { + wheel = false + }) - return false + return false + } }) container diff --git a/lib/jquery.simplr.smoothscroll.min.js b/lib/jquery.simplr.smoothscroll.min.js index e88a6c7..501bedd 100644 --- a/lib/jquery.simplr.smoothscroll.min.js +++ b/lib/jquery.simplr.smoothscroll.min.js @@ -1,2 +1,2 @@ /* jquery.simplr.smoothscroll version 1.1 copyright (c) 2012 https://github.com/simov/simplr-smoothscroll licensed under MIT */ -!function(e){"use strict";e.srSmoothscroll=function(t){var n,o=e.extend({step:55,speed:400,ease:"swing",target:e("body"),container:e(window)},t||{}),r=o.container,i=0,s=o.step,a=r.height(),c=!1;n="body"==o.target.selector?-1!==navigator.userAgent.indexOf("AppleWebKit")?o.target:e("html"):r,o.target.mousewheel(function(e,t){return c=!0,i=0>t?i+a>=o.target.outerHeight(!0)?i:i+=s:0>=i?0:i-=s,n.stop().animate({scrollTop:i},o.speed,o.ease,function(){c=!1}),!1}),r.on("resize",function(){a=r.height()}).on("scroll",function(){c||(i=r.scrollTop())})}}(jQuery); +!function(e){"use strict";e.srSmoothscroll=function(t){var o,n=e.extend({step:55,speed:400,ease:"swing",target:e("body"),container:e(window)},t||{}),r=n.container,i=0,s=n.step,a=r.height(),c=!1;o="body"==n.target.selector?-1!==navigator.userAgent.indexOf("AppleWebKit")?n.target:e("html"):r,n.target.mousewheel(function(e,t){return e.ctrlKey||e.metaKey?void 0:(c=!0,i=0>t?i+a>=n.target.outerHeight(!0)?i:i+=s:0>=i?0:i-=s,o.stop().animate({scrollTop:i},n.speed,n.ease,function(){c=!1}),!1)}),r.on("resize",function(){a=r.height()}).on("scroll",function(){c||(i=r.scrollTop())})}}(jQuery); \ No newline at end of file From a3dfe45b505936901dbd99276d5b47f68b31c564 Mon Sep 17 00:00:00 2001 From: Yura Griga Date: Wed, 24 Jun 2015 22:58:26 +0300 Subject: [PATCH 2/2] Set proper *top* value when init --- lib/jquery.simplr.smoothscroll.js | 10 ++++++---- lib/jquery.simplr.smoothscroll.min.js | 3 +-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/jquery.simplr.smoothscroll.js b/lib/jquery.simplr.smoothscroll.js index 266804b..c934994 100644 --- a/lib/jquery.simplr.smoothscroll.js +++ b/lib/jquery.simplr.smoothscroll.js @@ -21,7 +21,7 @@ // private fields & init var container = self.container - , top = 0 + , top = self.target.scrollTop() , step = self.step , viewport = container.height() , wheel = false @@ -40,11 +40,13 @@ wheel = true - if (delta < 0) // down + if (delta < 0){ + // down top = (top+viewport) >= self.target.outerHeight(true) ? top : top+=step - - else // up + } else { + // up top = top <= 0 ? 0 : top-=step + } target.stop().animate({scrollTop: top}, self.speed, self.ease, function () { wheel = false diff --git a/lib/jquery.simplr.smoothscroll.min.js b/lib/jquery.simplr.smoothscroll.min.js index 501bedd..152d08e 100644 --- a/lib/jquery.simplr.smoothscroll.min.js +++ b/lib/jquery.simplr.smoothscroll.min.js @@ -1,2 +1 @@ -/* jquery.simplr.smoothscroll version 1.1 copyright (c) 2012 https://github.com/simov/simplr-smoothscroll licensed under MIT */ -!function(e){"use strict";e.srSmoothscroll=function(t){var o,n=e.extend({step:55,speed:400,ease:"swing",target:e("body"),container:e(window)},t||{}),r=n.container,i=0,s=n.step,a=r.height(),c=!1;o="body"==n.target.selector?-1!==navigator.userAgent.indexOf("AppleWebKit")?n.target:e("html"):r,n.target.mousewheel(function(e,t){return e.ctrlKey||e.metaKey?void 0:(c=!0,i=0>t?i+a>=n.target.outerHeight(!0)?i:i+=s:0>=i?0:i-=s,o.stop().animate({scrollTop:i},n.speed,n.ease,function(){c=!1}),!1)}),r.on("resize",function(){a=r.height()}).on("scroll",function(){c||(i=r.scrollTop())})}}(jQuery); \ No newline at end of file +!function(e){"use strict";e.srSmoothscroll=function(t){var o,n=e.extend({step:55,speed:400,ease:"swing",target:e("body"),container:e(window)},t||{}),r=n.container,i=n.target.scrollTop(),s=n.step,a=r.height(),c=!1;o="body"==n.target.selector?-1!==navigator.userAgent.indexOf("AppleWebKit")?n.target:e("html"):r,n.target.mousewheel(function(e,t){return e.ctrlKey||e.metaKey?void 0:(c=!0,i=0>t?i+a>=n.target.outerHeight(!0)?i:i+=s:0>=i?0:i-=s,o.stop().animate({scrollTop:i},n.speed,n.ease,function(){c=!1}),!1)}),r.on("resize",function(e){a=r.height()}).on("scroll",function(e){c||(i=r.scrollTop())})}}(jQuery); \ No newline at end of file