Scroll to annotation on page load.
authorAlexandre Segura <mex.zktk@gmail.com>
Thu, 23 Feb 2017 11:49:47 +0100
changeset 354 1bcbdeb60eee
parent 353 a61f9a9ebdc9
child 355 004fdb42f063
Scroll to annotation on page load.
src/iconolab/templates/iconolab/detail_image.html
--- a/src/iconolab/templates/iconolab/detail_image.html	Wed Feb 22 18:42:39 2017 +0100
+++ b/src/iconolab/templates/iconolab/detail_image.html	Thu Feb 23 11:49:47 2017 +0100
@@ -31,7 +31,7 @@
         </div>
       {% else %}
         <div class="panel-body">
-          <div class="alert alert-warning">Pas d'annotation pour cette image</div>
+          <div class="alert alert-warning text-center">Pas d'annotation pour cette image</div>
         </div>
       {% endif %}
     </div>
@@ -155,12 +155,19 @@
     location.hash = '';
   });
 
+  function scrollTo($container, $el) {
+    $container.animate({
+      scrollTop:  $container.scrollTop() - $container.offset().top + $el.offset().top
+    }, 600);
+  }
+
   function router () {
     var url = location.hash.slice(1);
     if (url.length) {
       var annotation = url;
       var $el = $('.list-group a[data-annotation-id="'+annotation+'"]');
       displayAnnotation($el);
+      scrollTo($el.closest('.panel'), $el);
     }
   }
   // window.addEventListener('hashchange', router);