From 6546b7297b8e4ef8a2b12dfca941f34ac5953f66 Mon Sep 17 00:00:00 2001 From: Junaid Rasheed Date: Thu, 3 Nov 2016 12:34:35 +0200 Subject: [PATCH 1/7] fix window scroll to top each time page loaded which is kind of annoying in sidebar case --- lib/app/css/styleguide-app.css | 2 ++ lib/app/js/controllers/appCtrl.js | 2 +- lib/app/js/directives/preventBodyScroll.js | 35 ++++++++++++++++++++++ lib/app/views/main.html | 2 +- 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 lib/app/js/directives/preventBodyScroll.js diff --git a/lib/app/css/styleguide-app.css b/lib/app/css/styleguide-app.css index 07f8ba68..4b915879 100644 --- a/lib/app/css/styleguide-app.css +++ b/lib/app/css/styleguide-app.css @@ -389,6 +389,8 @@ Styleguide 3.1.1 display: inline-block; width: 30%; opacity: 1; + height: 500px; + overflow-y: scroll; @media (--mobile) { width: 100%; padding-top: 30px; diff --git a/lib/app/js/controllers/appCtrl.js b/lib/app/js/controllers/appCtrl.js index 2e77cc00..72807018 100644 --- a/lib/app/js/controllers/appCtrl.js +++ b/lib/app/js/controllers/appCtrl.js @@ -10,7 +10,7 @@ angular.module('sgApp') // Scroll top when page is changed $scope.$on('$viewContentLoaded', function() { - window.scrollTo(0, 0); + //window.scrollTo(0, 0); }); $scope.$on('progress start', function() { diff --git a/lib/app/js/directives/preventBodyScroll.js b/lib/app/js/directives/preventBodyScroll.js new file mode 100644 index 00000000..a81ca95e --- /dev/null +++ b/lib/app/js/directives/preventBodyScroll.js @@ -0,0 +1,35 @@ +'use strict'; + +angular.module('sgApp') +.directive('preventBodyScroll', function() { + return { + restrict: 'A', + link: preventBodyScroll + }; + + function preventBodyScroll(scope, element, attr) { + element.bind('wheel', preventScrollOnElement); + element.bind('mousewheel', preventScrollOnElement); + var target = element[0]; + + function preventScrollOnElement(ev) { + if (event.deltaY > 0) { + if (target.scrollTop + target.offsetHeight >= target.scrollHeight) { + ev.preventDefault(); + ev.returnValue = false; + return false; + } + } else { + if (target.scrollTop === 0) { + ev.preventDefault(); + ev.returnValue = false; + return false; + + } + } + + ev.returnValue = true; + return true; + } + } +}); diff --git a/lib/app/views/main.html b/lib/app/views/main.html index b0c80ff1..261dae90 100644 --- a/lib/app/views/main.html +++ b/lib/app/views/main.html @@ -68,7 +68,7 @@

Error: {{status.error.name}}

{{ toggleMenu ? ">>" : "<<" }}
-