From 11b6c185e1248516964b18bed8980e06576d5cec Mon Sep 17 00:00:00 2001 From: Luke McCollum Date: Mon, 17 Dec 2012 15:36:09 -0800 Subject: [PATCH 1/3] add an option to disable sensible scroll stopping --- portamento.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/portamento.js b/portamento.js index fd43bb4..41592b7 100755 --- a/portamento.js +++ b/portamento.js @@ -149,6 +149,7 @@ var wrapper = opts.wrapper; var gap = opts.gap; var disableWorkaround = opts.disableWorkaround; + var disableSensibleBehavior = opts.disableSensibleBehavior; var fullyCapableBrowser = positionFixedSupported(); if(panel.length != 1) { @@ -193,7 +194,7 @@ thisWindow.bind("scroll.portamento", function () { - if(thisWindow.height() > panel.outerHeight() && thisWindow.width() >= (thisDocument.width() - ieFix)) { // don't scroll if the window isn't big enough + if(disableSensibleBehavior || (thisWindow.height() > panel.outerHeight() && thisWindow.width() >= (thisDocument.width() - ieFix))) { // don't scroll if the window isn't big enough var y = thisDocument.scrollTop(); // current scroll position of the document @@ -227,7 +228,7 @@ thisWindow.bind("resize.portamento", function () { // stop users getting undesirable behaviour if they resize the window too small - if(thisWindow.height() <= panel.outerHeight() || thisWindow.width() < thisDocument.width()) { + if(!disableSensibleBehavior && (thisWindow.height() <= panel.outerHeight() || thisWindow.width() < thisDocument.width())) { if(panel.hasClass('fixed')) { panel.removeClass('fixed'); panel.css('top', '0'); @@ -257,7 +258,8 @@ $.fn.portamento.defaults = { 'wrapper' : $('body'), // the element that will act as the sliding panel's boundaries 'gap' : 10, // the gap (in pixels) left between the top of the viewport and the top of the panel - 'disableWorkaround' : false // option to disable the workaround for not-quite capable browsers + 'disableWorkaround' : false, // option to disable the workaround for not-quite capable browsers + 'disableSensibleBehavior' : false //option to stop scroll-stopping when the viewport is too small }; })(jQuery); \ No newline at end of file From 495928322b3689b52ac892ec2c57768ed92874d5 Mon Sep 17 00:00:00 2001 From: Luke McCollum Date: Tue, 18 Dec 2012 13:50:46 -0800 Subject: [PATCH 2/3] fix scroll to top on resize problem --- portamento.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/portamento.js b/portamento.js index 41592b7..02f542b 100755 --- a/portamento.js +++ b/portamento.js @@ -192,7 +192,7 @@ // --------------------------------------------------------------------------------------------------- - thisWindow.bind("scroll.portamento", function () { + thisWindow.bind("scroll.portamento", function (event) { if(disableSensibleBehavior || (thisWindow.height() > panel.outerHeight() && thisWindow.width() >= (thisDocument.width() - ieFix))) { // don't scroll if the window isn't big enough @@ -214,6 +214,7 @@ panel.css('position', 'absolute').animate({top: (0 - float_container.viewportOffset().top + gap)}); } } + event.preventDefault(); } else { // if we're above the top scroll boundary panel.removeClass('fixed'); From 2807fd525c8cf636a3f4f8290fd4ec9fe4449f35 Mon Sep 17 00:00:00 2001 From: Luke McCollum Date: Mon, 30 Nov 2015 16:05:32 -0800 Subject: [PATCH 3/3] add animation/transition support, fix broken on browser reload issue --- portamento.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/portamento.js b/portamento.js index 02f542b..a74d7ef 100755 --- a/portamento.js +++ b/portamento.js @@ -33,6 +33,10 @@ * http://jqueryfordesigners.com/fixed-floating-elements/ * */ +// Delegate .transition() calls to .animate() +// if the browser can't do CSS transitions. +if (!$.support.transition) + $.fn.transition = $.fn.animate; (function($){ $.fn.portamento = function(options) { @@ -199,7 +203,7 @@ var y = thisDocument.scrollTop(); // current scroll position of the document if (y >= (topScrollBoundary)) { // if we're at or past the upper scrolling boundary - if((panel.innerHeight() - wrapper.viewportOffset().top) - wrapperPaddingFix + gap >= wrapper.height()) { // if we're at or past the bottom scrolling boundary + if((panel.innerHeight() - wrapper.viewportOffset().top) - wrapperPaddingFix + gap >= wrapper[0].scrollHeight) { // if we're at or past the bottom scrolling boundary if(panel.hasClass('fixed') || thisWindow.height() >= panel.outerHeight()) { // check that there's work to do panel.removeClass('fixed'); panel.css('top', (wrapper.height() - panel.innerHeight()) + 'px'); @@ -211,7 +215,7 @@ panel.css('top', gap + 'px'); // to keep the gap } else { panel.clearQueue(); - panel.css('position', 'absolute').animate({top: (0 - float_container.viewportOffset().top + gap)}); + panel.css('position', 'absolute').transition({top: (0 - float_container.viewportOffset().top + gap)}); } } event.preventDefault();