From 1f2b24b30ba812716cf33af90b8f6ab1171d12c6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20St=C4=99pniowski?= Date: Mon, 22 Sep 2008 15:54:54 +0200 Subject: [PATCH] Start scroll only if anchor references existing element. --- wolnelektury/media/js/book.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/wolnelektury/media/js/book.js b/wolnelektury/media/js/book.js index fb4467f7b..41e3be28c 100644 --- a/wolnelektury/media/js/book.js +++ b/wolnelektury/media/js/book.js @@ -1,10 +1,12 @@ $(function() { function scrollToAnchor(anchor) { if (anchor) { - var name = anchor.slice(1); - $.scrollTo('a[name="' + name + '"]', 500, {offset: {top: -50, left: 0}}); - $('a[name="' + name + '"]').highlightFade('yellow'); - window.location.hash = '#' + name; + var element = $('a[name="' + anchor.slice(1) + '"]'); + if (element.length > 0) { + $.scrollTo(element, 500, {offset: {top: -50, left: 0}}); + $(element).highlightFade('yellow'); + window.location.hash = anchor; + } } } -- 2.20.1