From eabdbcc80495e7432cb54a8c86b41fe9b45e9c55 Mon Sep 17 00:00:00 2001 From: Athou Date: Sun, 26 May 2013 00:06:32 +0200 Subject: [PATCH] reset previous behavior --- src/main/webapp/js/directives.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/webapp/js/directives.js b/src/main/webapp/js/directives.js index ee4f7b23..09646e90 100644 --- a/src/main/webapp/js/directives.js +++ b/src/main/webapp/js/directives.js @@ -154,11 +154,16 @@ module.directive('scrollTo', [ '$timeout', function($timeout) { var elemTop = $(element).offset().top; var elemBottom = elemTop + $(element).height(); - var offset = parseInt(attrs.scrollToOffset, 10); - var scrollTop = $(element).offset().top + offset; - $('html, body').animate({ - scrollTop : scrollTop - }, 0); + if ((elemTop > docTop) && (elemBottom < docBottom)) { + // element is entirely visible + return; + } else { + var offset = parseInt(attrs.scrollToOffset, 10); + var scrollTop = $(element).offset().top + offset; + $('html, body').animate({ + scrollTop : scrollTop + }, 0); + } }); }); }