Skip to content
This repository has been archived by the owner on Jan 24, 2018. It is now read-only.

Commit

Permalink
don't jump to the hash on page load, only after init is called. refer…
Browse files Browse the repository at this point in the history
…ences #8, #12, #19
  • Loading branch information
Alexander Prinzhorn committed Oct 13, 2013
1 parent 3473eee commit 53281c5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
12 changes: 7 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,16 @@ <h1 id="wambo" data-menu-offset="-150">Wambo</h1>

<script type="text/javascript" src="../skrollr/dist/skrollr.min.js"></script>

<script type="text/javascript" src="dist/skrollr.menu.min.js"></script>
<script type="text/javascript" src="src/skrollr.menu.js"></script>

<script type="text/javascript">
var s = skrollr.init({
forceHeight: false
});
setTimeout(function() {
var s = skrollr.init({
forceHeight: false
});

skrollr.menu.init(s);
skrollr.menu.init(s);
}, 500);
</script>
</body>

Expand Down
22 changes: 13 additions & 9 deletions src/skrollr.menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
*/
var handleClick = function(e) {
//Only handle left click.
if((e.which || e.button) !== 1) {
if(e.which !== 1 && e.button !== 0) {
return;
}

Expand Down Expand Up @@ -116,6 +116,16 @@
return true;
};

var jumpStraightToHash = function() {
if(window.location.hash && document.querySelector) {
var link = document.querySelector('a[href="' + window.location.hash + '"]');

if(link) {
handleLink(link, true);
}
}
};

var defer = function(fn) {
window.setTimeout(fn, 1);
};
Expand Down Expand Up @@ -154,6 +164,8 @@
});
}, false);
}

jumpStraightToHash();
};

//Private reference to the initialized skrollr.
Expand All @@ -168,14 +180,6 @@
defer(function() {
if(window.location.hash) {
window.scrollTo(0, 0);

if(document.querySelector) {
var link = document.querySelector('a[href="' + window.location.hash + '"]');

if(link) {
handleLink(link, true);
}
}
}
});
}(document, window));

0 comments on commit 53281c5

Please sign in to comment.