From 9620b6238d9d3afba19c6e1e99afba3356fdff9e Mon Sep 17 00:00:00 2001 From: OldHawk Date: Sun, 23 Apr 2017 16:06:31 +0800 Subject: [PATCH] add directive scrollIf, scroll to comment when reply --- .../directives/scrollIf.client.directive.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 modules/core/client/directives/scrollIf.client.directive.js diff --git a/modules/core/client/directives/scrollIf.client.directive.js b/modules/core/client/directives/scrollIf.client.directive.js new file mode 100644 index 00000000..4cee884b --- /dev/null +++ b/modules/core/client/directives/scrollIf.client.directive.js @@ -0,0 +1,27 @@ +(function () { + 'use strict'; + + angular.module('core') + .directive('scrollIf', scrollIf); + + scrollIf.$inject = ['$uiViewScroll', '$location', '$anchorScroll']; + + function scrollIf($uiViewScroll) { + var directive = { + restrict: 'A', + link: link + }; + + return directive; + + function link(scope, element, attrs) { + scope.$watch(attrs.scrollIf, function (value) { + if (value) { + //element[0].scrollIntoView({block: 'end', behavior: 'smooth'}); + //$uiViewScroll(element); + window.scrollTo(0, element[0].offsetTop - 60) + } + }); + } + } +}());