提交 657d9903 编写于 作者: J Johan Preynat

Fix: don't try to scroll when hash doesn't exist on current page

上级 ba030fb8
......@@ -26,6 +26,11 @@ function scrollToHash(hash) {
var $scroller = getScroller(),
dest = 0;
// Don't try to scroll if element doesn't exist
if (!pageHasElement(hash)) {
return;
}
if (hash) {
dest = getElementTopPosition(hash);
}
......@@ -43,6 +48,16 @@ function scrollToHash(hash) {
setChapterActive(null, hash);
}
/*
Return wether the element exists on the page
*/
function pageHasElement(id) {
var $scroller = getScroller(),
$el = $scroller.find(id);
return !!$el.length;
}
/*
Return the top position of an element
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册