From 8dfab132230321e01187f95db7dc08bc975435d7 Mon Sep 17 00:00:00 2001 From: yura Date: Tue, 27 Oct 2015 13:55:36 +0200 Subject: [PATCH 1/2] Add onTopHandler functionality. --- src/jquery.scrollUp.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/jquery.scrollUp.js b/src/jquery.scrollUp.js index 445df9b..cb04009 100644 --- a/src/jquery.scrollUp.js +++ b/src/jquery.scrollUp.js @@ -99,6 +99,9 @@ if (triggerVisible) { $self[animOut](animSpeed); triggerVisible = false; + if (o.onTopHandler && typeof o.onTopHandler == 'function'){ + o.onTopHandler(); + } } } }); @@ -138,7 +141,8 @@ scrollTitle: false, // Set a custom title if required. Defaults to scrollText scrollImg: false, // Set true to use image activeOverlay: false, // Set CSS color to display scrollUp active point, e.g '#00FFFF' - zIndex: 2147483647 // Z-Index for the overlay + zIndex: 2147483647, // Z-Index for the overlay + onTopHandler: null // Performing when page scroll up }; // Destroy scrollUp plugin and clean all modifications to the DOM From db1e495cb756fa82384918b07eef90af43abcb9b Mon Sep 17 00:00:00 2001 From: yura Date: Sun, 8 Nov 2015 12:36:57 +0200 Subject: [PATCH 2/2] Add ontop.scrollup event. Modify readme and demo. Update devDependencies. --- README.md | 27 +++++++++++++++++++++++++-- demo/css/labs.css | 6 ++++-- demo/index.html | 18 ++++++++++++++++++ dist/jquery.scrollUp.js | 6 +++++- dist/jquery.scrollUp.min.js | 2 +- package.json | 4 ++-- src/jquery.scrollUp.js | 8 ++++---- 7 files changed, 59 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 7ea4263..6c16e63 100644 --- a/README.md +++ b/README.md @@ -56,16 +56,39 @@ Example: `activeOverlay: '#00FFFF'`. +

Events Demo

+

For demo purposes, toggle the ontop.scrollup event.

+
Attach ontop.scrollup event +

Dummy content

Dummy content to ensure the page is long enough to scroll on all screen sizes.

diff --git a/dist/jquery.scrollUp.js b/dist/jquery.scrollUp.js index 191f16e..7a397af 100644 --- a/dist/jquery.scrollUp.js +++ b/dist/jquery.scrollUp.js @@ -105,6 +105,7 @@ if (triggerVisible) { $self[animOut](animSpeed); triggerVisible = false; + $(window).trigger('ontop.scrollup'); } } }); @@ -144,7 +145,7 @@ scrollTitle: false, // Set a custom title if required. Defaults to scrollText scrollImg: false, // Set true to use image activeOverlay: false, // Set CSS color to display scrollUp active point, e.g '#00FFFF' - zIndex: 2147483647 // Z-Index for the overlay + zIndex: 2147483647, // Z-Index for the overlay }; // Destroy scrollUp plugin and clean all modifications to the DOM @@ -156,10 +157,13 @@ // If 1.7 or above use the new .off() if ($.fn.jquery.split('.')[1] >= 7) { $(window).off('scroll', scrollEvent); + // remove scrollup events namespace + $(window).off('.scrollup'); // Else use the old .unbind() } else { $(window).unbind('scroll', scrollEvent); + $(window).unbind('ontop.scrollup'); } }; diff --git a/dist/jquery.scrollUp.min.js b/dist/jquery.scrollUp.min.js index aa79e47..d0deb0b 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,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,n,i,a,p,d=l.fn.scrollUp.settings=l.extend({},l.fn.scrollUp.defaults,r),f=!1;switch(p=d.scrollTrigger?l(d.scrollTrigger):l("",{id:d.scrollName,href:"#top"}),d.scrollTitle&&p.attr("title",d.scrollTitle),p.appendTo("body"),d.scrollImg||d.scrollTrigger||p.html(d.scrollText),p.css({display:"none",position:"fixed",zIndex:d.zIndex}),d.activeOverlay&&l("
",{id:d.scrollName+"-active"}).css({position:"absolute",top:d.scrollDistance+"px",width:"100%",borderTop:"1px dotted"+d.activeOverlay,zIndex:d.zIndex}).appendTo("body"),d.animation){case"fade":s="fadeIn",t="fadeOut",c=d.animationSpeed;break;case"slide":s="slideDown",t="slideUp",c=d.animationSpeed;break;default:s="show",t="hide",c=0}n="top"===d.scrollFrom?d.scrollDistance:l(e).height()-l(o).height()-d.scrollDistance,i=l(o).scroll(function(){l(o).scrollTop()>n?f||(p[s](c),f=!0):f&&(p[t](c),f=!1,l(o).trigger("ontop.scrollup"))}),d.scrollTarget?"number"==typeof d.scrollTarget?a=d.scrollTarget:"string"==typeof d.scrollTarget&&(a=Math.floor(l(d.scrollTarget).offset().top)):a=0,p.click(function(o){o.preventDefault(),l("html, body").animate({scrollTop:a},d.scrollSpeed,d.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).off(".scrollup")):(l(o).unbind("scroll",r),l(o).unbind("ontop.scrollup"))},l.scrollUp=l.fn.scrollUp}(jQuery,window,document); \ No newline at end of file diff --git a/package.json b/package.json index 5c57396..ec0decc 100644 --- a/package.json +++ b/package.json @@ -33,13 +33,13 @@ "back to top" ], "devDependencies": { - "del": "^1.1.1", + "del": "^2.0.2", "gulp": "^3.8.11", "gulp-header": "^1.2.2", "gulp-jshint": "^1.9.4", "gulp-rename": "^1.2.0", "gulp-uglify": "^1.1.0", - "jshint-stylish": "^1.0.1" + "jshint-stylish": "^2.0.1" }, "engines": { "node": ">=0.10.3" diff --git a/src/jquery.scrollUp.js b/src/jquery.scrollUp.js index cb04009..8026113 100644 --- a/src/jquery.scrollUp.js +++ b/src/jquery.scrollUp.js @@ -99,9 +99,7 @@ if (triggerVisible) { $self[animOut](animSpeed); triggerVisible = false; - if (o.onTopHandler && typeof o.onTopHandler == 'function'){ - o.onTopHandler(); - } + $(window).trigger('ontop.scrollup'); } } }); @@ -142,7 +140,6 @@ scrollImg: false, // Set true to use image activeOverlay: false, // Set CSS color to display scrollUp active point, e.g '#00FFFF' zIndex: 2147483647, // Z-Index for the overlay - onTopHandler: null // Performing when page scroll up }; // Destroy scrollUp plugin and clean all modifications to the DOM @@ -154,10 +151,13 @@ // If 1.7 or above use the new .off() if ($.fn.jquery.split('.')[1] >= 7) { $(window).off('scroll', scrollEvent); + // remove scrollup events namespace + $(window).off('.scrollup'); // Else use the old .unbind() } else { $(window).unbind('scroll', scrollEvent); + $(window).unbind('ontop.scrollup'); } };