diff --git a/dist/jquery.scrollUp.js b/dist/jquery.scrollUp.js index 191f16e..900dc2e 100644 --- a/dist/jquery.scrollUp.js +++ b/dist/jquery.scrollUp.js @@ -96,10 +96,21 @@ // Scroll function scrollEvent = $(window).scroll(function () { + var scrollPos = $(window).scrollTop(); if ($(window).scrollTop() > scrollDis) { if (!triggerVisible) { $self[animIn](animSpeed); triggerVisible = true; + }else{ + if(o.hideWhenStill){ + setTimeout(function(){ + // If scollPos matches current scroll position after hesitation time, apply animOut. + if(scrollPos === $(window).scrollTop()){ + $self[animOut](animSpeed); + triggerVisible = false; + } + }, o.hideHesitation); + } } } else { if (triggerVisible) { @@ -138,6 +149,8 @@ easingType: 'linear', // Scroll to top easing (see http://easings.net/) animation: 'fade', // Fade, slide, none animationSpeed: 200, // Animation in speed (ms) + hideWhenStill: false, // Hide element after scroll stops + hideHesitation: 2500, // Time to leave element visible after scroll stops scrollTrigger: false, // Set a custom triggering element. Can be an HTML string or jQuery object scrollTarget: false, // Set a custom target element for scrolling to. Can be element or number scrollText: 'Scroll to top', // Text for element, can contain HTML diff --git a/dist/jquery.scrollUp.min.js b/dist/jquery.scrollUp.min.js index aa79e47..c5fa26d 100644 --- a/dist/jquery.scrollUp.min.js +++ b/dist/jquery.scrollUp.min.js @@ -4,4 +4,4 @@ * Copyright (c) Mark Goodyear — @markgdyr — http://markgoodyear.com * License: MIT */ -!function(l,o,e){"use strict";l.fn.scrollUp=function(o){l.data(e.body,"scrollUp")||(l.data(e.body,"scrollUp",!0),l.fn.scrollUp.init(o))},l.fn.scrollUp.init=function(r){var s,t,c,i,n,a,d,p=l.fn.scrollUp.settings=l.extend({},l.fn.scrollUp.defaults,r),f=!1;switch(d=p.scrollTrigger?l(p.scrollTrigger):l("",{id:p.scrollName,href:"#top"}),p.scrollTitle&&d.attr("title",p.scrollTitle),d.appendTo("body"),p.scrollImg||p.scrollTrigger||d.html(p.scrollText),d.css({display:"none",position:"fixed",zIndex:p.zIndex}),p.activeOverlay&&l("
",{id:p.scrollName+"-active"}).css({position:"absolute",top:p.scrollDistance+"px",width:"100%",borderTop:"1px dotted"+p.activeOverlay,zIndex:p.zIndex}).appendTo("body"),p.animation){case"fade":s="fadeIn",t="fadeOut",c=p.animationSpeed;break;case"slide":s="slideDown",t="slideUp",c=p.animationSpeed;break;default:s="show",t="hide",c=0}i="top"===p.scrollFrom?p.scrollDistance:l(e).height()-l(o).height()-p.scrollDistance,n=l(o).scroll(function(){l(o).scrollTop()>i?f||(d[s](c),f=!0):f&&(d[t](c),f=!1)}),p.scrollTarget?"number"==typeof p.scrollTarget?a=p.scrollTarget:"string"==typeof p.scrollTarget&&(a=Math.floor(l(p.scrollTarget).offset().top)):a=0,d.click(function(o){o.preventDefault(),l("html, body").animate({scrollTop:a},p.scrollSpeed,p.easingType)})},l.fn.scrollUp.defaults={scrollName:"scrollUp",scrollDistance:300,scrollFrom:"top",scrollSpeed:300,easingType:"linear",animation:"fade",animationSpeed:200,scrollTrigger:!1,scrollTarget:!1,scrollText:"Scroll to top",scrollTitle:!1,scrollImg:!1,activeOverlay:!1,zIndex:2147483647},l.fn.scrollUp.destroy=function(r){l.removeData(e.body,"scrollUp"),l("#"+l.fn.scrollUp.settings.scrollName).remove(),l("#"+l.fn.scrollUp.settings.scrollName+"-active").remove(),l.fn.jquery.split(".")[1]>=7?l(o).off("scroll",r):l(o).unbind("scroll",r)},l.scrollUp=l.fn.scrollUp}(jQuery,window,document); \ No newline at end of file +!function(l,e,o){"use strict";l.fn.scrollUp=function(e){l.data(o.body,"scrollUp")||(l.data(o.body,"scrollUp",!0),l.fn.scrollUp.init(e))},l.fn.scrollUp.init=function(r){var t,s,i,c,n,a,d,p=l.fn.scrollUp.settings=l.extend({},l.fn.scrollUp.defaults,r),f=!1;switch(d=p.scrollTrigger?l(p.scrollTrigger):l("",{id:p.scrollName,href:"#top"}),p.scrollTitle&&d.attr("title",p.scrollTitle),d.appendTo("body"),p.scrollImg||p.scrollTrigger||d.html(p.scrollText),d.css({display:"none",position:"fixed",zIndex:p.zIndex}),p.activeOverlay&&l("",{id:p.scrollName+"-active"}).css({position:"absolute",top:p.scrollDistance+"px",width:"100%",borderTop:"1px dotted"+p.activeOverlay,zIndex:p.zIndex}).appendTo("body"),p.animation){case"fade":t="fadeIn",s="fadeOut",i=p.animationSpeed;break;case"slide":t="slideDown",s="slideUp",i=p.animationSpeed;break;default:t="show",s="hide",i=0}c="top"===p.scrollFrom?p.scrollDistance:l(o).height()-l(e).height()-p.scrollDistance,n=l(e).scroll(function(){var o=l(e).scrollTop();l(e).scrollTop()>c?f?p.hideWhenStill&&setTimeout(function(){o===l(e).scrollTop()&&(d[s](i),f=!1)},p.hideHesitation):(d[t](i),f=!0):f&&(d[s](i),f=!1)}),p.scrollTarget?"number"==typeof p.scrollTarget?a=p.scrollTarget:"string"==typeof p.scrollTarget&&(a=Math.floor(l(p.scrollTarget).offset().top)):a=0,d.click(function(e){e.preventDefault(),l("html, body").animate({scrollTop:a},p.scrollSpeed,p.easingType)})},l.fn.scrollUp.defaults={scrollName:"scrollUp",scrollDistance:300,scrollFrom:"top",scrollSpeed:300,easingType:"linear",animation:"fade",animationSpeed:200,hideWhenStill:!1,hideHesitation:2500,scrollTrigger:!1,scrollTarget:!1,scrollText:"Scroll to top",scrollTitle:!1,scrollImg:!1,activeOverlay:!1,zIndex:2147483647},l.fn.scrollUp.destroy=function(r){l.removeData(o.body,"scrollUp"),l("#"+l.fn.scrollUp.settings.scrollName).remove(),l("#"+l.fn.scrollUp.settings.scrollName+"-active").remove(),l.fn.jquery.split(".")[1]>=7?l(e).off("scroll",r):l(e).unbind("scroll",r)},l.scrollUp=l.fn.scrollUp}(jQuery,window,document); \ No newline at end of file diff --git a/src/jquery.scrollUp.js b/src/jquery.scrollUp.js index 445df9b..dcc2c48 100644 --- a/src/jquery.scrollUp.js +++ b/src/jquery.scrollUp.js @@ -90,10 +90,21 @@ // Scroll function scrollEvent = $(window).scroll(function () { + var scrollPos = $(window).scrollTop(); if ($(window).scrollTop() > scrollDis) { if (!triggerVisible) { $self[animIn](animSpeed); triggerVisible = true; + }else{ + if(o.hideWhenStill){ + setTimeout(function(){ + // If scollPos matches current scroll position after hesitation time, apply animOut. + if(scrollPos === $(window).scrollTop()){ + $self[animOut](animSpeed); + triggerVisible = false; + } + }, o.hideHesitation); + } } } else { if (triggerVisible) { @@ -132,6 +143,8 @@ easingType: 'linear', // Scroll to top easing (see http://easings.net/) animation: 'fade', // Fade, slide, none animationSpeed: 200, // Animation in speed (ms) + hideWhenStill: false, // Hide element after scroll stops + hideHesitation: 2500, // Time to leave element visible after scroll stops scrollTrigger: false, // Set a custom triggering element. Can be an HTML string or jQuery object scrollTarget: false, // Set a custom target element for scrolling to. Can be element or number scrollText: 'Scroll to top', // Text for element, can contain HTML